Jump to content

File upload... File not there?


Lashiec

Recommended Posts

I've had a weird re-occuring problem with file uploads that I can't seem to track the problem. I have multiple sites, so different servers, and it seems that every now and then when I upload a file and try to resize it (imagecreatefromjpeg) that it can't seem to find the image stream? I'm not sure why this happens sometimes and most of the time the file works just fine.

 

I also noticed that after this happens, if I attempt to move the file (on my HD) to a new folder or something (still on my HD) that Windows will come back with an error saying that the file is in use or can't be modified. It's not just one server or one computer that does this either, I have a client that uploads images and the site resizes them. Every now and then I get a call and they say it's not working... Well, I go in and it works for me and then it works for them again later, and nothing was ever changed.

 

Some sample code, in this program I take the $_FILES['tmp_name'] and pass that into a function which (if it needs to resize) it'll then take that and put it into this image class that I built. Inside the class it goes something like:

 

$this->stream = imagecreatefromjpeg($this->file);
$this->image = imagecreatetruecolor($this->width, $this->height);
imagecopyresized($this->image,$this->stream,0,0,$this->offset_x,$this->offset_y,$this->width,$this->height,$this->old_width,$this->old_height);
imagejpeg($this->image,$filename,'75');

 

There's some more in the code, but that's really all that is being ran. The rest is behind if statements that never get executed based on the uploads I'm doing.

 

Yeah, I'm not really sure what could be causing the problem. And the fact that it only occurs every now and then really gets me.

Link to comment
Share on other sites

Try this tutorial first:

http://www.zymic.com/tutorials/php/creating-a-file-upload-form-with-php/

 

Read it, try it (get it to work at least once) and then try to troubleshoot your code. It seems you are using PHP classes (thus a lot of code involved), so getting the concept of uploading files using PHP will be hard to comprehend.

 

Cheers!

Angel

Link to comment
Share on other sites

I'll give it a shot tomorrow when I'm at work. I'll try getting one of my programs to give me the error with file uploads (although the error is usually something like it can't find the image file to get the image size/width since it does that first). Then, I'll try running the same file through the example you posted and see if it works.

 

And yeah, I've got quite a few classes going on in my program. The only one that gets hit when I upload an image is the image class that takes care of resizing (and adding padding/backgrounds, but I don't use that here). Otherwise, if it doesn't need to resize the image it actually just does move_uploaded_file($file, "upload/$loc/$section/$filename");, but I guess everytime I've gotten the error I've told it to resize.

Link to comment
Share on other sites

well if it's sometimes working and sometimes not, that more than likely means its a problem with conditions.

 

That's what gets me. I can try to upload abc.jpg and have it fail, then 20 minutes later upload abc.jpg again and it'll go through, resize, and be just fine. It's a really hard thing to track, because it just seems to act as if the file isn't there. I check in firebug and look at the posted values and it shows that it uploaded an image and all too.

 

I'll check into it a little more tomorrow, I do have some javascript form validation going on, but I don't think that I validate an image upload box, and even then, it shouldn't alter the file before it uploads.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.