PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi,
I use the script below to rename the uploaded image files. THe script works fine but I would like to use as filename the product_id taken from my recordset.
When I try to use $row_prod['prod_id'] which is the value that returns my id in the $rename variable , i get a renamed file without name but just an extension ( .jpg)
If you're getting ".jpg" then clearly $rename is empty. You say that you've set it to the contents of $row_prod['prod_id'] .. that would imply that $row_prod['prod_id'] is empty too.
You should also be aware that the extension of a file is meaningless. Just because it ends in .jpg doesn't mean it actually is a .jpg file. Furthermore, the way your code is written, if I were to upload a file called virus.jpg.exe then you would save it in your website as "Anything.jpg" .. and users would download it .. I would recommend looking at the $_FILES['Image']['type'] upload data .. that gives you the MIME type of a file that's been uploaded. It's not completely bulletproof as it can still be faked, but it's much, much more reliable than the extension.
The $row_prod['prod_id'] is not empty. It gets the value from a URL parameter. When I try to put it in a table with an echo I can see its value, so i guess its ok but when i use it in the &rename variable I get a blank filename.
Whats wrong ???
There is no security problem because the file will be used only by the admin of the page. He will only upload images