Help with image uploading on my site

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

Help with image uploading on my site

Post by Billh93 on Thu Dec 06, 2012 6:12 pm
([msg=71564]see Help with image uploading on my site[/msg])

How can I get rid of this error: "getimagesize() [function.getimagesize]: Filename cannot be empty". Everytime I don't upload a picture this pops up. Here is the code thats making trouble
Code: Select all
list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']);
Billh93
New User
New User
 
Posts: 15
Joined: Sun Nov 27, 2011 5:26 pm
Blog: View Blog (0)


Re: Help with image uploading on my site

Post by LoGiCaL__ on Fri Dec 07, 2012 6:34 am
([msg=71578]see Re: Help with image uploading on my site[/msg])

Billh93 wrote:How can I get rid of this error: "getimagesize() [function.getimagesize]: Filename cannot be empty". Everytime I don't upload a picture this pops up. Here is the code thats making trouble
Code: Select all
list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']);


Why don't you test to see if $_FILES(['new_picture']['tmp_name']) exists first and if it does, then run that line of code? Something like:

Code: Select all

if(file_exists($_FILES['new_picture']['tmp_name']))
  list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']);




If that doesn't work then just test that the length of the image name is greater than 0.

Code: Select all
if(strlen($_FILES['new_picture']['name']) > 0)
  list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']);
User avatar
LoGiCaL__
Addict
Addict
 
Posts: 1060
Joined: Sun May 30, 2010 12:33 pm
Blog: View Blog (0)


Re: Help with image uploading on my site

Post by mShred on Sat Dec 08, 2012 12:30 pm
([msg=71594]see Re: Help with image uploading on my site[/msg])

If I remember correctly, this is an issue of the inputted file. I've had to mess with this kinda stuff before. Check to make sure the variable you're using is actually declared, and that the picture in question is valid. The function you're using requires all that shit because of previous security hazards. If that weren't true, I would have found an easier way into this jewelry store's site that I was pentesting.
Image

For those about to rock.
User avatar
mShred
Administrator
Administrator
 
Posts: 1716
Joined: Tue Jun 22, 2010 4:22 pm
Blog: View Blog (2)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests