Hello people!
I would like to know how to remove white space and replace them with a "_" on the file uploaded by this script.
<?php
// Check if a file has been uploaded
if(isset($_FILES['uploaded_file'])) {
// Make sure the file was sent without errors
if($_FILES['uploaded_file']['error'] == 0) {
// Connect to the database
$dbLink = new mysqli('xxxxxx', 'xxxxxxx', 'xxxxxxxx', 'xxxxxxxx');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
$userid = $_SESSION['loginid']; //login session
$target = "f/".$userid."_";
$target = $target . basename( $_FILES['uploaded_file']['name']);
// Gather all required data
$description = $_POST['description'];
$name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
$mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
// delete this line $data = $dbLink->real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name']));
$size = intval($_FILES['uploaded_file']['size']);
if($description)
{
if (strlen($description)>400)
echo "Description can't be more than 400 characters!<br><a href='index.php?page=user_files2'>[Go back]</a>";
else
{
// Create the SQL query
//add userid to your database delete the data entity.
$query = "
INSERT INTO `userfile2` (
`userid`, `name`, `mime`, `description`, `size`, `created`
)
VALUES ('{$userid}',
'{$name}', '{$mime}', '{$description}', {$size}, NOW()
)";
// Execute the query
$result = $dbLink->query($query);
// Check if it was successfull
if($result) {
move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target);
echo 'Success! Your file was successfully added!';
}
else {
echo 'Error! Failed to insert the file'
. "<pre>{$dbLink->error}</pre>";
}
}
}
else {
echo 'An error accured while the file was being uploaded. '
. 'Error code: '. intval($_FILES['uploaded_file']['error']);
}
$file1 = $_FILES['uploaded_file']['name'];
// Close the mysql connection
}
else {
echo 'Error! Your file was not sent!';
}
// Echo a link back to the main page
echo '';
}
$dbLink->close();
?>
<br>
<a href="f/<?php echo "" . $userid . "_" . $file1?>">Download</a><br>
<p><font color="#000000"><b>Direct Link:</b></font></p>
<input type="text" value="www.xxxx.com/f/<?php echo "" . $userid . "_" . $file1?>" class="button1">
I have no clue how to do it and i just hope some of you got a snippet, my list for the user's files wont work without it!
/peace