move_uploaded_file()以与Zend好好尝试一下工作(move_uploaded_f

2019-07-29 12:03发布

我们正在建设的Zend框架内的应用程序,并有麻烦移动上传的文件。 我们得到了$文件路径= $形式 - >图像 - 文件>的getFileName(); 但是,当我们试图在其上运行move_uploaded_file,它只是返回false。

图像被成功地被上传到临时目录,但我们不能将其移动到文件夹中。

   $formData = $request->getPost();
        if ($form->isValid($formData)) 
        {
              $form->image->receive();
              $filePath = $form->image->getFileName();
               move_uploaded_file($filePath,APPLICATION_PATH . '\images\new');
         }

提前致谢

编辑:

当我尝试,我得到500 - 内部服务器错误:

            $upload = new Zend_File_Transfer_Adapter_Http();

            $upload->setDestination("C:\xx\xx\public\banners");

            if (!$upload->isValid()) 
             {
                 throw new Exception('Bad image data: '.implode(',', $upload->getMessages()));
              }

      try {
        $upload->receive();
       } 
       catch (Zend_File_Transfer_Exception $e) 
       {
           throw new Exception('Bad image data: '.$e->getMessage());
       }

它似乎是 “$ upload-> setDestination(” C:\ XX \ XX \ PUBLIC \横幅 “);” 导致崩溃

Answer 1:

:这相当于问题及答案在计算器应该帮助你使用Zend Framework 1.7.4文件上传

//validate file
//for example, this checks there is exactly 1 file, it is a jpeg and is less than 512KB
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Count', false, array('min' =>1, 'max' => 1))
       ->addValidator('IsImage', false, 'jpeg')
       ->addValidator('Size', false, array('max' => '512kB'))
       ->setDestination('/tmp');

if (!$upload->isValid()) 
{
    throw new Exception('Bad image data: '.implode(',', $upload->getMessages()));
}

try {
        $upload->receive();
} 
catch (Zend_File_Transfer_Exception $e) 
{
        throw new Exception('Bad image data: '.$e->getMessage());
}

//then process your file, it's path is found by calling $upload->getFilename()

使用后->receive()你已经移动上传文件,以便调用另一个move_uploaded_file()是毫无意义的。



文章来源: move_uploaded_file() with Zend doens't work