简体   繁体   English

图片上传顺序错误

[英]Images upload in the wrong order

I am aware it's an old script (an old way of doing things). 我知道这是一个旧脚本(做事的一种旧方法)。 The script works, however, the images do not upload in the right order. 该脚本有效,但是图像未按正确的顺序上传。 I am not exactly sure but it looks to me they upload from last to first instead of from first to last. 我不确定,但是在我看来,他们是从最后到第一而不是从最后到最后上传。 What makes it do that? 是什么使它做到了?

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]);
    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,
            picfile = '$newfile'";
            mysql_query($sql);
            if (mysql_error())
            {

                ...

If by "order" you mean the order that you selected the images in a multiple file input, you cannot rely on that order being consistent on the back end. 如果用“顺序”表示在多个文件输入中选择图像的顺序,则不能依赖于后端一致的顺序。 It varies by browser and server: does multiple upload follow the same order of uploading in which we select the images? 它随浏览器和服务器的不同而不同: 多次上传是否遵循我们选择图像的相同上传顺序?

If you are always seeing the order reversed, perhaps you need to change some code in the script that serves them up ( ASC instead of DESC ). 如果您总是看到顺序颠倒了,也许您需要在提供它们的脚本中更改一些代码( ASC而不是DESC )。

One way you could keep the order consistent is by sending another variable to the server on upload that contains an array of the file names in order, then base your INSERT order off of that array, not the order of the $_FILES array. 保持顺序一致的一种方法是,在上传时向服务器发送另一个变量,该变量包含顺序排列的文件名数组,然后将INSERT顺序基于该数组,而不是$_FILES数组的顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM