gpt4 book ai didi

php - 上传多个文件导致同一个文件上传4次

转载 作者:行者123 更新时间:2023-11-28 13:19:18 24 4
gpt4 key购买 nike

这段 javascript 代码广告被修改为上传的图片数量等于 4。这个效果很好,因为它总是下载 4 张图片,但它为所有图片带来相同的路径,相同的图片是四次。请注意,我使用随机数生成器来确保图片是唯一的。

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');
}
}
});

});

处理所有下载的 block 是:

<?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

最佳答案

我看不出是什么导致了您的问题,因为您提供的信息不充分。看起来你正在使用 AjaxUpload ,它很旧,不再受支持。如果我是正确的,请考虑升级到由同一作者 Fine Uploader 替换 AjaxUpload 的库.您可能会发现许多问题/问题在升级后都得到了解决。

关于php - 上传多个文件导致同一个文件上传4次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14783873/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com