Lashiec Posted February 19, 2009 Share Posted February 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145859-file-upload-file-not-there/ Share on other sites More sharing options...
angelcool Posted February 19, 2009 Share Posted February 19, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/145859-file-upload-file-not-there/#findComment-765797 Share on other sites More sharing options...
Lashiec Posted February 19, 2009 Author Share Posted February 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145859-file-upload-file-not-there/#findComment-765802 Share on other sites More sharing options...
.josh Posted February 19, 2009 Share Posted February 19, 2009 well if it's sometimes working and sometimes not, that more than likely means its a problem with conditions. Quote Link to comment https://forums.phpfreaks.com/topic/145859-file-upload-file-not-there/#findComment-765804 Share on other sites More sharing options...
Lashiec Posted February 19, 2009 Author Share Posted February 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145859-file-upload-file-not-there/#findComment-765812 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.