简体   繁体   English

上载多个文件导致同一文件上载4次

[英]Upload multiple files lead to upload 4 time de same file

This piece of javascript code ad been modified to have a number of pictures uploaded equal to 4. This work well since it'always download 4 picture but it bring the same path for all picture witch is four time the same picture. 这段javascript代码广告已修改为具有等于4张上传的图片。由于始终下载4张图片,所以效果很好,但是所有图片的相同路径是同一张图片的四倍。 Note I uses a randon number generator to be sure the picture is unique. 注意我使用randon数生成器来确保图片是唯一的。

i=0;
    $(function(){
        var btnUpload=$('#upload');
        var status=$('#status');
        new AjaxUpload(btnUpload, {
            action: 'upload-file.php',
            name: 'uploadfile',
            onSubmit: function(file, ext){
                 if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
                    // extension is not allowed 
                    status.text('Only JPG, PNG or GIF files are        allowed');
                return false;
            }
            else if(i>=4){addClass('error');}
            status.text('Uploading...');
        },
        onComplete: function(file, response){
            //On completion clear the status
            status.text('');
            //Add uploaded file to list
            if(response==="success"&&i<=3){
                $('<li></li>').appendTo('#files').html('<img src="./uploads/'+file+'" alt="" /><br />'+file).addClass('success');
            i++;} else{
                $('<li></li>').appendTo('#files').text(file).addClass('error');
            }
        }
    });

    });

The block for the treatment of all the download is: 处理所有下载的代码块是:

<?php
session_start();
if($_SESSION['upload-file'] == "AAA"){$_SESSION['upload-file']=0;}
$uploaddir = 'uploads/'; 
$random_digit = rand(0,1000000);
$file = $uploaddir.$random_digit.basename($_FILES['uploadfile']['name']);     
  if($_SESSION['upload-file'] == 0){$_SESSION['Photo1'] = $file;$_SESSION['upload-     file']++;}
  if($_SESSION['upload-file'] == 1){$_SESSION['Photo2'] = $file;$_SESSION['upload-file']++;}
  if($_SESSION['upload-file'] == 2){$_SESSION['Photo3'] = $file;$_SESSION['upload-file']++;} 
  if($_SESSION['upload-file'] == 3){$_SESSION['Photo4'] = $file;$_SESSION['upload-file']++;$_SESSION['upload-file']="AAA";}

if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { 
  echo "success"; 

} else {
    echo "error";
}

the variable $_SESSION['upload-file'] ='AAA'; is only to create a loop.
So the block up there goes into file end_temp_p.php and the second block is upload-file.php
This donwload 4 time the same file wich look like a paradox

I can't see what is causing your problem, as the information you have provided is not sufficient. 我看不到是什么原因导致了您的问题,因为您提供的信息还不够。 It looks like you are using AjaxUpload , which is quite old and not supported anymore. 看来您正在使用AjaxUpload ,它已经很旧了,不再受支持。 If I am correct, consider upgrading to the library that replaces AjaxUpload, by the same author, Fine Uploader . 如果我是正确的,请考虑由同一作者Fine Uploader升级到替换AjaxUpload的库。 You will likely find that many of your problems/questions are addressed after upgrading. 升级后,您可能会发现许多问题/问题已得到解决。

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

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