Log in

View Full Version : PHP image uploader help...



qwikad.com
01-09-2014, 06:46 PM
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.





<?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++;
}
}










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

<?php
}
?>





Any help is appreciated.

traq
01-10-2014, 12:44 AM
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.

qwikad.com
01-10-2014, 01:08 AM
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?

traq
01-10-2014, 05:14 AM
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.

rahulvyas
01-27-2014, 04:06 PM
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