Uploading One File Two Different Ways

See all posts Reply

Uploading One File Two Different Ways new!
by Erik Greif, 9 years, 9 months ago
I am trying to upload the same file twice. Once as a thumbnail (128x128 scaled) and a second time as the original image.

I'm not sure if this place accepts BB code or anything so I'll give you a link to my current file: https://dl.dropboxusercontent.com/u/57282495/Temporary/upload_photo.zip

I originally built this from an example. This script works flawlessly if I comment out either one of the upload processes. As you see, I have now named the second upload process under a different $handle/$handle2 name, but it didn't make a difference. My server times out (30 seconds) on line 5010 of class.upload.php, sometimes 5013 or 5007, which are all inside a couple of nested for loops. I get the idea one of them is looping infinitely because the server always kills it inside of the loop at 4999:
for ($y = 0; $y < $this->image_dst_y; $y++) {
which is for jpg and bmp files.

So down to my point: I need to render two copies of the same upload, and quite frankly I know next to nothing about this upload script/library/class, although it is quite fantastic. Thanks a ton to anyone who can help me.Reply
Re: Uploading One File Two Different Ways new!
by colin, 9 years, 9 months ago
At a glance, your code looks fine. That said, you could use only one instance of the class, see the main code example on the site.

As for the script crashing, it may be because you are running out of memory. try your code with a small picture to see if this is the issue.Reply
Re: Uploading One File Two Different Ways new!
by Erik Greif, 9 years, 9 months ago
For all uploads, regardless of size, the second upload I do (thumbnail or simple upload) always throws these errors:

Warning: getimagesize(D:\webserver\tmp\phpD256.tmp): failed to open stream: No such file or directory in F:\Software Development\(PHP) SpychMed International\HTDOCS\scripts\upload\class.upload.php on line 2984

Warning: fopen(D:\webserver\tmp\phpD256.tmp): failed to open stream: No such file or directory in F:\Software Development\(PHP) SpychMed International\HTDOCS\scripts\upload\class.upload.php on line 3043

Warning: move_uploaded_file(D:\webserver\tmp\phpD256.tmp): failed to open stream: No such file or directory in F:\Software Development\(PHP) SpychMed International\HTDOCS\scripts\upload\class.upload.php on line 3776

Warning: move_uploaded_file(): Unable to move 'D:\webserver\tmp\phpD256.tmp' to '../../content/\9cf6b785c383aae2406774fe13912cee.jpg' in F:\Software Development\(PHP) SpychMed International\HTDOCS\scripts\upload\class.upload.php on line 3776
error : Can't create the temporary file. Can't carry on a process.
Reply
Re: Uploading One File Two Different Ways new!
by colin, 9 years, 9 months ago
Remove the first $handle->clean();, since you're processing the same file twice.Reply
Re: Uploading One File Two Different Ways new!
by Erik Greif, 9 years, 9 months ago
Worked great!
But.. now back to the first problem. If I am running out of memory (on the larger files it still times out) what should I do? The file I am uploading is less than 1.5 megabytes. I have plenty of memory on my server system, I'm just not sure how to allocate more.Reply
Re: Uploading One File Two Different Ways new!
by colin, 9 years, 9 months ago
Search for memory in the site, or click here.

You can also check this post.

You need to raise the PHP memory limit, usually in php.ini. On shared hosting, you probably can't edit your php.ini, so you can try the following, although it will work only if the hosting company allows it, which they usually don't.

You can add this in your script:
ini_set ( "memory_limit", "40M")

Or in a .htaccess file:
php_value memory_limit 40M

If the above doesn't work, ask your hosting company.Reply
Re: Uploading One File Two Different Ways new!
by Erik Greif, 9 years, 9 months ago
I am currently hosting this at my own server since the domain doesn't exist yet. I think GoDaddy will have such options already turned up when I use them.
However on my server when I add that line to the script, the page works fine until I click upload, and then I get a blank page.
I've determined that the script dies right at the first
if ($handle->processed) { 
( dunno if the BBS is going to work )
Any ideas?Reply
Re: Uploading One File Two Different Ways new!
by colin, 9 years, 9 months ago
Check your webserver's log. You are probably running out of memory.Reply
Re: Uploading One File Two Different Ways new!
by Erik Greif, 9 years, 9 months ago
No. My PHP memory limit is set to "memory_limit = 128M" so I don't think that's the problem. Sorry to drag this out, but do you have any other ideas?Reply
Re: Uploading One File Two Different Ways new!
by colin, 9 years, 9 months ago
128MB may not be enough for images with a lot of pixels.

Besides, your webserver's log will tell you why the script crashes.Reply
Re: Uploading One File Two Different Ways new!
by Erik Greif, 9 years, 9 months ago
I am getting no info errors in Apache, but PHP just has the error I saw on screen.

[20-Jun-2014 15:02:48 US/Pacific] PHP Fatal error: Maximum execution time of 30 seconds exceeded in F:\Software Development\(PHP) SpychMed International\HTDOCS\scripts\upload\class.upload.php on line 5006

I have another domain with GoDaddy, which is where this is going to end up. So I just tested the code again, and while it took ages to upload, it did. Since we're here, might I ask how to set a maximum size (dimensions) for an upload? That way I can have a large image version, but it won't be over a certain number of pixels, like width*length.Reply
Re: Uploading One File Two Different Ways new!
by colin, 9 years, 9 months ago
I see, I missed your error. Your server seems quite slow. Anyhow, you can increase the PHP time limit in your script.

As for limiting the images that can be uploaded, check out image_max_width, image_max_height, and image_max_pixels.Reply
Re: Uploading One File Two Different Ways new!
by Erik Greif, 9 years, 9 months ago
Oh yes, my network card is having a lot of trouble. I get about 2 maybe 3 megabits up and down right now at best. Just awful. I'll be replacing it soon. However, I don't want to necessarily block large images. I want to downsize large images that are over a certain number of pixels.Reply
Re: Uploading One File Two Different Ways new!
by Erik Greif, 9 years, 9 months ago
It seems as if image_ratio, image_x, and image_y can achieve an image under a given width and height... am I right?
Just reading the documentation. Very unusual behavior for me.Reply
Re: Uploading One File Two Different Ways new!
by colin, 9 years, 9 months ago
I am not too sure I understand what you mean by "achieve".

image_ratio_xxx, image_x and image_y are used to resize an image.

Note that when you instantiate the class, you can read the images data with image_src_x, image_src_y and image_src_pixels and act accordingly.Reply
Re: Uploading One File Two Different Ways new!
by Erik Greif, 9 years, 9 months ago
Okay so all of the above worked great with an if check on the original resolution. ALL GOOD :) Starting a new topic for something else though.Reply