我对一个错误很生气,更像是没有错误,我不明白。我正在尝试通过 Zend_Framework 将文件上传到目录。
这是我的php:
if (($this->_request->getPost('file_upload', false))) {
if ($this->view->form->isValid($_POST)) {
$data = $this->view->form->getValues();
Zend_Debug::dump($data);
if (!file_exists(APPLICATION_PATH . "/../docs_client")) {
mkdir(APPLICATION_PATH . "/../docs_client");
}
if (!file_exists(APPLICATION_PATH . "/../docs_client/" . $id . "/" . $data['annonce_id'])) {
mkdir(APPLICATION_PATH . "/../docs_client/" . $id . "/" . $data['annonce_id'], 0700, true);
}
$dirName = APPLICATION_PATH . "/../docs_client/" . $id . "/" . $data['annonce_id'] . '/';
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination($dirName);
if ($data['accord'] != NULL) {
$accord = $adapter->getFileInfo('accord');
Zend_Debug::dump($accord);
$accordInfo = $accord['accord'];
$name = $accordInfo['name'];
$extension = pathinfo($accordInfo['name'], PATHINFO_EXTENSION);
$fname = "accord_bailleur_" . $id . "_" . $data['annonce_id'] . '_' . uniqid() . '.' . strtolower($extension);
$adapter->addFilter(new Zend_Filter_File_Rename(array(
'target' => $fname,
'overwrite' => true
)), null, $accord);
if (!$adapter->receive($accord)){
//die ( print_r ( $adapter->getMessages (), 1 ) );
}
Zend_Debug::dump($fname);
//Zend_Debug::dump($accord);die();
}
}
}
在我的 zend 表单中,我将 valueDisabled 设置为 true。在我的 html 表单中,我将 enctype 设置为“multipart/form-data”
当我尝试上传我的文件时,如果缺少目录,则会创建目录,除了我的文件没有上传之外,一切都像它应该做的那样。我的临时目录或我设置的上传目录中没有任何内容。当我尝试显示错误时,我有一个空数组。
这是我的调试:
/* POST DATA */
array(4) {
["accord"] => string(36) "0b4f7b468ad649ccbe8d2c78d3f50389.pdf"
["loyer"] => NULL
["justificatif"] => NULL
["annonce_id"] => string(3) "337"
}
/* CONTENT OF $accord*/
array(1) {
["accord"] => array(11) {
["name"] => string(36) "0b4f7b468ad649ccbe8d2c78d3f50389.pdf"
["type"] => string(15) "application/pdf"
["tmp_name"] => string(27) "C:\Windows\Temp\phpE10B.tmp"
["error"] => int(0)
["size"] => string(7) "3258008"
["options"] => array(4) {
["ignoreNoFile"] => bool(false)
["useByteString"] => bool(true)
["magicFile"] => NULL
["detectInfos"] => bool(true)
}
["validated"] => bool(false)
["received"] => bool(false)
["filtered"] => bool(false)
["validators"] => array(1) {
[0] => string(25) "Zend_Validate_File_Upload"
}
["destination"] => string(86) "C:\Program Files (x86)\Zend\Apache2\htdocs\esubletz1\application/../docs_client/17/337"
}
}
/* CONTENT OF $fname*/
string(40) "accord_bailleur_17_337_5224634612c1d.pdf"
对于另一个文件上传,我或多或少有相同的代码,它工作正常。
我不明白为什么这个没有。