Results 1 to 5 of 5

Thread: PHP image uploader help...

  1. #1
    Join Date
    Oct 2012
    Posts
    145
    Thanks
    18
    Thanked 1 Time in 1 Post

    Default PHP image uploader help...

    Right now when you upload images the smaller size images get uploaded first. The whole upload process is overall random.

    How can I tell this image uploader to upload images in the right order from the first to the last? In other words, the second image shouldn't start uploading until the first one has uploaded. The third image shouldn't start uploading until the second one has uploaded... etc., etc.

    Code:
    
    <?php
    		}
    
    
    		// Upload pictures
    		if (count($_FILES['pic']['tmp_name']))
    		{
    			$ipval = ipval();
    			$uploaderror = 0;
    			$uploadcount = 0;
    
    			$errorMessages = array();
    
    
    			foreach ($_FILES['pic']['tmp_name'] as $k=>$tmpfile)
    			{
    				if ($tmpfile)
    				{
    					$thisfile = array("name"=>$_FILES['pic']['name'][$k],
    						"tmp_name"=>$_FILES['pic']['tmp_name'][$k],
    						"size"=>$_FILES['pic']['size'][$k],
    						"type"=>$_FILES['pic']['type'][$k],
    						"error"=>$_FILES['pic']['error'][$k]);			
    
    					// Check size
    					if ($_FILES['pic']['size'][$k] > $pic_maxsize*1000)
    					{
    
    					    $errorMessages[] = $thisfile['name'] . " - " . $lang['ERROR_UPLOAD_PIC_TOO_BIG'];
    
    						$uploaderror++;
    					}
    					elseif (!isValidImage($thisfile))
    					{
    
    					    $errorMessages[] = $thisfile['name'] . " - " . $lang['ERROR_UPLOAD_PIC_BAD_FILETYPE'];
    
    						$uploaderror++;
    					}
    					else
    					{
    
    						$newfile = SaveUploadFile($thisfile, "{$path_escape}{$datadir['adpics']}", TRUE, $images_max_width, $images_max_height);
    
    						if($newfile)
    						{
    						    $sql = "INSERT INTO $t_adpics
    									SET adid = $adid,
    										isevent = '$data[isevent]',
    										picfile = '$newfile'";
    							mysql_query($sql);
    
    							if (mysql_error())
    							{
    
    								$errorMessages[] = $thisfile['name'] . " - " . $lang['ERROR_UPLOAD_PIC_INTERNAL'];
    
    								$uploaderror++;
    							}
    							else
    							{
    								$uploadcount++;
    							}
    
    						}
    						else
    						{
    
        						echo "<!-- {$k} - Permission error; can not copy -->";
    						    $errorMessages[] = $thisfile['name'] . " - " . $lang['ERROR_UPLOAD_PIC_INTERNAL'];
     
    							$uploaderror++;
    						}
    					}
    
    				}
    				elseif ($_FILES['pic']['name'][$k])
    				{
    
    				    echo "<!-- {$k} - Temp file not present -->";
    
    					$uploaderror++;
    				}
    			}


    Code:
    		<?php
    		for ($i=1; $i<=$pic_count; $i++)
    		{	
    		?>
    			<input type="file" name="pic[]" size="69">
    
    		<?php
    		}
    		?>


    Any help is appreciated.
    Last edited by qwikad.com; 01-09-2014 at 06:18 PM.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Short answer: no. Deciding when/how to upload files is the browser's job. You would have to give each upload its own form, and submit them one-at-a-time via javascript.

    The reason the smaller file is arriving first is probably because it's smaller - it takes less time to move over the wire. What is your actual problem? Do you simply need to know what order they were in in the form? You could assign each file input a unique name.

  3. #3
    Join Date
    Oct 2012
    Posts
    145
    Thanks
    18
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by traq View Post
    Short answer: no. Deciding when/how to upload files is the browser's job. You would have to give each upload its own form, and submit them one-at-a-time via javascript.

    The reason the smaller file is arriving first is probably because it's smaller - it takes less time to move over the wire. What is your actual problem? Do you simply need to know what order they were in in the form? You could assign each file input a unique name.
    The actual problem is when someone uploads, let's say, 5 pics, the first image is expected to become a thumbnail preview. When the pics are uploaded randomly (smaller sizes first), the thumbnail preview becomes the one that uploaded first. So if a user uploads a pic of a house and then a pic of a shed, obviously they expect the house to be the preview, not the shed.

    I'd actually even go for this solution: The first file input should have a unique name, so that I could pull that image as a thumbnail preview. The rest of the files can upload anyway they want. The question is, how do I do it?

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by qwikad.com View Post
    I'd actually even go for this solution: The first file input should have a unique name, so that I could pull that image as a thumbnail preview. The rest of the files can upload anyway they want. The question is, how do I do it?
    …by giving the first file input a unique name? I mean, that is how you would do it, so I'm not sure what your question is.

    Of course, there's no reason you couldn't give every file input a unique name, and then you could return all the images in the same order they were submitted.

  5. #5
    Join Date
    Jan 2014
    Location
    India
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I really like class upload. You cannot just upload and resize (with quality settings), but also crop, cut, watermark, fill, rotate, flip, convert, bevel, overlay, frame, etc. For more info; www.verot.net/php_class_upload_samples.htm
    Last edited by traq; 01-27-2014 at 03:46 PM. Reason: removed hotlink

Similar Threads

  1. Multiple Image Uploader
    By multichild in forum PHP
    Replies: 0
    Last Post: 03-23-2012, 04:09 PM
  2. making a handy image uploader for family
    By baconDelta in forum PHP
    Replies: 4
    Last Post: 01-02-2012, 04:18 AM
  3. Multi-image uploader for auction site
    By katzrmine in forum Looking for such a script or service
    Replies: 0
    Last Post: 10-16-2009, 12:23 PM
  4. uploader
    By nokotin in forum JavaScript
    Replies: 3
    Last Post: 11-11-2006, 12:30 PM
  5. uploader
    By moonshadow in forum JavaScript
    Replies: 3
    Last Post: 03-30-2006, 01:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •