Renaming image uploads to specific names
Posted: Wed Aug 23, 2006 3:18 pm
Hi, I'm using a form to upload a jpeg image to my server via PHP (see code). I'd like to rename the jpeg as title.jpg before uploading it to the server and also I'd like to reject the image if it isn't exactly 500x375 pixels.
I've searched the net but can only find a few tutorials about renaming files with random file names in order to avoid overwriting old ones but I actually want to overwrite old image files so I want to rename files to a specific name rather than to a random one. I can't find much either about checking an image's pixel dimensions.
Thanks so much for all your help – leao
I've searched the net but can only find a few tutorials about renaming files with random file names in order to avoid overwriting old ones but I actually want to overwrite old image files so I want to rename files to a specific name rather than to a random one. I can't find much either about checking an image's pixel dimensions.
Thanks so much for all your help – leao
Code: Select all
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']);
$ok=1;
if ($uploaded_size > 70000)
{
echo "Your file is too large.<br>";
$ok=0;
}
if ($uploaded_type != 'image/jpeg') {
echo "You may only upload JPEG files.<br>";
$ok=0;
}
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ".
basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>