move_uploaded_file() con Zend no funciona

We're building an application within Zend framework and are having trouble moving an uploaded file. We get the file by $filePath = $form->image->getFileName(); but when we're trying to run move_uploaded_file on it, it just returns false.

The image is successfully being uploaded to the temp directory, but we can't move it into a folder.

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

Gracias por adelantado

EDIT:

When I try this, I get 500 - internal server error:

            $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());
       }

It seems that it is the " $upload->setDestination("C:\xx\xx\public\banners"); " that cause the crash

preguntado el 22 de mayo de 12 a las 19:05

1 Respuestas

This equivalent question & answer on stackoverflow should help you out: Carga de archivos usando 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()

Después de usar ->receive() you have already moved the uploaded file so calling another move_uploaded_file() es inútil

contestado el 23 de mayo de 17 a las 12:05

Hi, thanks for your answer. I edit my question above with your suggestions. I get a crash :( - ratón negro

@user1251004 Don't know if this will change anything but try this: "C:\\xx\\xx\\public\\banners". Note the double slashes. - rick kupers

@user1251004 have a look in your error logs see what it says about the 500. - rick kupers

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.