Replace space with underscore, then upload file
Posted: Fri Dec 18, 2009 10:57 pm
Hey guys. I've got a nagging problem. I've got a small file uploading site and I want to replace the spaces in a file name with underscores and then upload that file with the new name. In what way can I do this best? Please include some code, because I don't really understand the script very well. The one thing I think I know is that I need to use but the only thing I don't know is where to substitute it in my script. Any help?
Here's my code:
Code: Select all
$replaced = str_replace(" ","_",$target);Here's my code:
Code: Select all
<?php
$yn = $_POST['yn'];
$email = $_POST['email'];
$target = "../../uploads/";
$target2 = basename( $_FILES['uploaded']['name']);
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "Please make sure that this is your file: <b>$target2</b><br><br>
<table>
<tr><td><form action=\"../create\" method=\"GET\">
<input name=\"email\" value=\"$email\" type=\"hidden\" />
<input name=\"uploaded\" value=\"$target2\" type=\"hidden\" />
<input name=\"yn\" value=\"$yn\" type=\"hidden\" />
<input type=\"submit\" value=\"Yes, continue uploading\" />
</form></td>
<td>
<form action=\"../../cancel\" method=\"GET\">
<input name=\"email\" value=\"$email\" type=\"hidden\">
<input name=\"yn\" value=\"$yn\" type=\"hidden\">
<input name=\"file\" value=\"../$target2\" type=\"hidden\" />
<input type=\"submit\" value=\"No, cancel upload\" />
</form></td></tr>
</table> ";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>