我知道这里已经有不少话题了,而且我已经阅读了其中的很多内容,但都无济于事。我有一个表单用于上传带有说明的多个文件。如果用户需要多个上传/描述字段,他们可以点击链接通过jquery添加另一个。该窗体的代码是:php/jquery多文件上传
<form action="adm.php?mode=upload" method="post">
<input type="hidden" name="article_id" value="<?php echo $article_id; ?>" />
<input type="hidden" name="new_path" value="<?php echo $new_path; ?>" />
<div id="files">
<div id="file" class="row">
<input type="file" name="file[]" id="file" /><br />
Description:<br />
<textarea name="desc[]" cols="50" rows="5"></textarea>
</div>
</div>
<div>
<input type="submit" name="submit" value="Submit" />
</div>
</form>
<a href="#" id="add_upload">Add File</a>
点击add_upload时
<div id="file" class="row">
<input type="file" name="file[]" id="file" /><br />
Description:<br />
<textarea name="desc[]" cols="50" rows="5"></textarea>
</div>
的克隆被附加到文件DIV。 ?
我相信这是根据php.net的<input type="file" name="file[]" id="file" />
正确使用,然而在adm.php模式听众脚本=上传从来没有在提交收到$ _FILES数组:
case 'upload' :
$path = request_var('new_path', '');
$article_id = request_var('article_id', 0);
$error = array();
$messages = array();
if(isset($_FILES['file']['tmp_name']))
{
// Number of uploaded files
$num_files = count($_FILES['file']['tmp_name']);
//create the directory if it doesn't exist already
if(!is_dir($path))
{
mkdir($path);
}
/** loop through the array of files ***/
for($i=0; $i < $num_files;$i++)
{
// check if there is a file in the array
if(!is_uploaded_file($_FILES['file']['tmp_name'][$i]))
{
$messages[] = 'No file uploaded';
}
else
{
// copy the file to the specified dir
if(@copy($_FILES['file']['tmp_name'][$i],$path.'/'.$_FILES['file']['name'][$i]))
{
$messages[] = $_FILES['file']['name'][$i].' uploaded';
}
else
{
/*** an error message ***/
$messages[] = 'Uploading '.$_FILES['file']['name'][$i].' Failed';
}
}
}
}
else
{
$messages[] = 'No files set for upload??';
}
$err_msg = $messages;
include($root_path.'pages/header.php');
include($root_path.'pages/error.php');
include($root_path.'pages/column.php');
include($root_path.'pages/footer.php');
exit;
休息;
我总是得到“没有文件设置为上传?”错误,因为文件没有被传输。所有其他值都通过POST发送并且没有问题地接收。我究竟做错了什么?
var_dump你的$ _POST和$ _FILE变量,看看里面有什么。 – profitphp
var_dump:'array(5){[“article_id”] => string(2)“24”[“new_path”] => string(30)“images/gallery/family_outings /”[“file”] = > array(2){[0] => string(12)“DSC01121.jpg”[1] => string(12)“DSC01126.jpg”} [“desc”] => array(2){[ => string(5)“test1”[1] => string(5)“test2”} [“submit”] => string(6)“Submit”} array {0} { – chaoskreator
数组在最后是$ _FILES – chaoskreator