Hi all, I found a simple file upload script I want to incorporate in my site so users can post images with their text posts. I got it working but for security purposes I would like to simply append .jpg to the end of whatever filename they upload. So if they upload:
gimmedatpassword.cgi
The file will be renamed to:
gimmedatpassword.cgi.jpg
My thoughts behind this are to prevent files from being interpreted as anything but JPG. Can you guys figure out how to add .jpg to the filename? I guess I don't quite understand whats going on well enough in the script to be able to myself. Its fairly small:
Here is the input html form:
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="userfile"><p>
<input type="submit" value="Upload File">
</form>
Here is the php script which uploads the file:
<?php
// check the filesize
if($_FILES['userfile']['size'] > 2000000)
{
echo "The file is too big! It must be less than or equal to 20 Kilobytes";
exit;
}
if(is_uploaded_file($FILES['userfile']['tmp_name'
]))
{
move_uploaded_file($FILES['userfile']['tmp_name']
,'uploads/'.$_FILES['userfile']['name']);
echo "upload completed!";
}
else
{
echo "<b>ERROR</b>";
}
?>
any help appricated, thanks!