help. i finally put together a script to upload only .png IMAGE files that are under a certain filesize. BUT. is there any way i can only upload the image if its dimensions are exactly 55x55? heres what i have so far: (i want it always be named avi.png so only one image can be in the folder)

if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {

$avisize=$_FILES['userfile']['size'];
$avitype=$_FILES['userfile']['type'];
$aviname=$_FILES['userfile']['name'];
$aviname="avi.png";
$avipath=$_SERVER["DOCUMENT_ROOT"] . "/" . $_SESSION[userfilefoldername] . "/" . $aviname;
 if ($avisize<100000 && ereg("image", $avitype) && $_FILES[userfile][type] == "image/png")
{move_uploaded_file($_FILES['userfile']['tmp_name'],
$avipath);
$aviroot= "http://www.socialemo.com/$_SESSION[userfilefoldername]/";
$avipath2=$aviroot . $aviname;
echo "<h3>Your Image Link Here: </h3><a target="_blank" href='$avipath2'>$avipath2</a>";}

 if ($avisize>100000)
{
echo "ERROR <br> the image size is too big";
}

if (!ereg("image", $avitype) )
{
echo "ERROR <br> the file is not image<br>";
}
if ($_FILES[userfile][type] != "image/png"){
echo "ERROR <br> the file is not .png must be a png image<br>";}



}

You can use getimagesize to determine the dimensions of your image.
http://us.php.net/function.getimagesize Using getimagesize you can have your script upload only if the dimensions match the criteria you specify. It may be easier for you to just resize the image upon upload to the size you want, but you run the risk of warping the image.

how do i use getimagesize()
to find the size of the image BEFORE it uploads?

and if i cant get the dimensions before it uploads, how can i delete it after it uploads without using unlink()?

I hope someone corrects me if I am wrong, but I assumed it would work both before or after upload. I know for sure that it works after upload but I guess that's not helping you much. I would think something like

$aviname=$_FILES['userfile']['name'];
$aviname="avi.png";
$imgsize = getimagesize($aviname);

Off the top of my head unlink is the only way I can think of, it's all I ever use and I don't ever have problems with it.

I hope someone corrects me if I am wrong, but I assumed it would work both before or after upload. I know for sure that it works after upload but I guess that's not helping you much. I would think something like

$aviname=$_FILES['userfile']['name'];
$aviname="avi.png";
$imgsize = getimagesize($aviname);

i got
Warning: getimagesize(avi.png) [function.getimagesize]: failed to open stream: No such file or directory in..

but i figured out how to do it after the upload.. cause there will be a stream.

but i have to delete the file if its not 55x55 and i cant use unlink(). is it really the only way to delete a file?

list($width_orig, $height_orig) = getimagesize($_FILES['userfile']['name']);

should create 2 varaibles names $width_orig & $height_orig with the values you requires.

A tip would be instead of forcing users to resize images themselves, why not let PHP do it?

Why is it that you can't use unlink?

list($width_orig, $height_orig) = getimagesize($_FILES['userfile']['name']);

should create 2 varaibles names $width_orig & $height_orig with the values you requires.

A tip would be instead of forcing users to resize images themselves, why not let PHP do it?

Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in

i dont understand what should i do? i usered userfile then i used $aviname

nevermind i think i did $userfile or something now it works thanks a lot!
i need them to care about their avi

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.