1

Zend フレームワーク内でアプリケーションを構築していますが、アップロードされたファイルの移動に問題があります。$filePath = $form->image->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\banners"); " のようです

4

1 に答える 1

2

スタックオーバーフローに関するこの同等の質問と回答が役に立ちます: 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()

于 2012-05-22T18:54:32.987 に答える