I have a PHP application.
I allow users to upload files to my web application.
Question: What's the best way for me to sanitize the file names of the uploaded documents $_FILES["filename"]["tmp_name"]
in PHP?
UPDATE:
Can I take an MD5 of the uploaded filename and use that as the newly assigned filename? If so, how do I do that in PHP?
You can simply change the name of the file by changing the name of the file in the second parameter of move_uploaded_file . $temp = explode(".", $_FILES["file"]["name"]); $newfilename = round(microtime(true)) . '.
$_FILES['file']['tmp_name'] - The temporary filename of the file in which the uploaded file was stored on the server.
I bet that you also store some information about the file in the database. If this is correct, then you can use the primary key (ID) as a filename on your server and preserve the original filename in the database. This gives you greater flexibility, because you can manipulate the metadata without renaming the actual file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With