0
如何判斷這是多重上傳的控制器或型號。所以一個一個地移動它們。爲單一上傳以下模型作品。如何上傳多個文件?
// html
<input type=file name=moreattachment[] />
<input type=file name=moreattachment[] />
/* Controller */
$file = $_FILES['moreattachment']['name'];
foreach($_FILES['moreattachment']['name'] as $k)
{
Zend_Debug::dump($k);
//Application_Model_File::mvFile(); // let us move 1 by 1
}
/* Model - how do you handle the moreattachment[] ? */
public static function mvFile()
{
$fname = basename($_FILES['moreattachment']['name']);
$_fname = strtolower (end(explode('.',$fname)));
switch($_fname)
{
case ($_fname == 'jpg' ||
$_fname == 'jpeg' ||
$_fname == 'gif' ||
$_fname == 'bmp' ||
$_fname == 'png' ||
$_fname == 'html' ||
$_fname == 'pdf' ||
$_fname == 'doc' ||
$_fname == 'docx' ||
$_fname == 'xls'
):
$target_path = APPLICATION_PATH . "/../public/files/attachment/";
//chmod("../up" , 0777);
$target_path = $target_path . basename($_FILES['moreattachment']['name']);
if(move_uploaded_file($_FILES['moreattachment']['tmp_name'], $target_path)) {
}else{
}
break;
}
return $fname;
}
output of $_FILE
["moreattachment"] => array(5) {
["name"] => array(2) {
[0] => string(4) "celt"
[1] => string(4) "celt"
}
["type"] => array(2) {
[0] => string(24) "application/octet-stream"
[1] => string(24) "application/octet-stream"
}
["tmp_name"] => array(2) {
[0] => string(14) "/tmp/phpf9QqF0"
[1] => string(14) "/tmp/php4NLRLu"
}
["error"] => array(2) {
[0] => int(0)
[1] => int(0)
}
["size"] => array(2) {
[0] => int(11238)
[1] => int(11238)
}
}
uploadify.com ..;) – Calum 2011-01-24 10:59:04
那豈不是更容易使用Zend_Form和Zend_Form_Element_File元素來處理您的上傳? – Marcin 2011-01-24 11:27:37