php - Zend\File\Transfer\Adapter\Http on receive : error "File was not found" with jQuery File Upload -


here 2 questions problem

zf2 file upload jquery file upload - file not found

can't blueimp / jquery-file-upload , zf2 running

without ansers. , i'm create issue on zf2 code examples. github.com/zendframework/zf2/issues/6291

and have request developer on email question, how implement jquery file upload zf2.

github.com/blueimp/jquery-file-upload

so, there real problem many peple, , no manuals, no answers. please, before send me read documentation, notice, i'm spend many hours on problem , read documentation , not i'm have problem.

please, write manual code examples, how implement it. or answer, why have error , how resolve it?

there i'm copy example zf2 issue.

i'm try use jquery-file-upload copy standard tpl, include css , scrypts , it's work, send files controller. controller doesn't work.

here code

public function processjqueryaction()     {         $request   = $this->getrequest();         $response  = $this->getresponse();         $jsonmodel = new \zend\view\model\jsonmodel();          if ($request->ispost()) {              try {                 $datas          = [];                 $datas['files'] = [];                 $uploadpath     = $this->getfileuploadlocation();                 $uploadfiles    = $this->params()->fromfiles('files');  //                throw new \exception(json_encode("files " . serialize($_files)));                  // Сохранение выгруженного файла                 $adapter = new \zend\file\transfer\adapter\http();                 $adapter->setdestination($uploadpath);                 $adapter->setvalidators(array(                     new \zend\validator\file\extension(array(                         'extension' => array('jpg', 'jpeg', 'png', 'rtf')                             )                     ), //                    new \zend\validator\file\upload()                 ));                  if (!$adapter->isvalid()) {                     throw new \exception(json_encode("!isvalid " . implode(" ", $adapter->getmessages())));                 }                  $files = $adapter->getfileinfo(); //                throw new \exception(json_encode($files));                  foreach ($files $file => $info) { //                    throw new \exception(json_encode($info));                      $name = $adapter->getfilename($file);                      // file uploaded & valid                     if (!$adapter->isuploaded($file)) {                         throw new \exception(json_encode("!isuploaded") . implode(" ", $adapter->getmessages()));                         continue;                     }                      if (!$adapter->isvalid($file)) {                         throw new \exception(json_encode("!isvalid " . implode(" ", $adapter->getmessages())));                         continue;                     }                      // receive files user directory                     $check = $adapter->receive($file); // has on top                      if (!$check) {                         throw new \exception(json_encode("! receive" . implode(" ", $adapter->getmessages())));                     }                      /**                      * "name": "picture1.jpg",                       "size": 902604,                       "url": "http:\/\/example.org\/files\/picture1.jpg",                       "thumbnailurl": "http:\/\/example.org\/files\/thumbnail\/picture1.jpg",                       "deleteurl": "http:\/\/example.org\/files\/picture1.jpg",                       "deletetype": "delete"                      */                     $fileclass             = new stdclass();                     // stripped out image thumbnail our purpose, security reasons                     // add in here.                     $fileclass->name       = $name;                     $fileclass->size       = $adapter->getfilesize($name);                     $fileclass->type       = $adapter->getmimetype($name);                     $fileclass->deleteurl  = '/uploads/delete';                     $fileclass->deletetype = 'delete';                     //$fileclass->error = 'null';                     $fileclass->url        = '/';                      $datas['files'][] = $fileclass;                 }                  $response->getheaders()->addheaders(array(                     'pragma'        => 'no-cache',                     'cache-control' => 'private, no-cache',                     "content-type"  => 'application/json'                 ));  //                return $response->setcontent(json_encode(array('files' => $files)));                 return $response->setcontent(json_encode($datas));             } catch (\exception $e) {                  return $response->setcontent(json_encode($e->getmessage()));             }         }          return $jsonmodel;  } 

sorry debug code, can see, i'm try hard make work, on 3 hours.

error "file 'cimg0042.jpg' not found"

when i'm call $adapter->isvalid() or when call file name, same error. path, files uploaded, correct , writable. $_files array exist , valid.

here $_files json

files a:1:{s:5:\"files\";a:5:{s:4:\"name\";a:1:{i:0;s:28:\"52876065d17dce0a7472e5d6.jpg\";}s:4:\"type\";a:1:{i:0;s:10:\"image\/jpeg\";}s:8:\"tmp_name\";a:1:{i:0;s:14:\"\/tmp\/phpmft2mb\";}s:5:\"error\";a:1:{i:0;i:0;}s:4:\"size\";a:1:{i:0;i:82640;}}} 

and result of $files = $adapter->getfileinfo();

"{"files_0_":{"name":"52876065d17dce0a7472e5d6.jpg","type":"image\/jpeg","tmp_name":"\/tmp\/phpf6voo9","error":0,"size":"82640","options":{"ignorenofile":false,"usebytestring":true,"magicfile":null,"detectinfos":true},"validated":false,"received":false,"filtered":false,"validators":["zend\\validator\\file\\upload","zend\\validator\\file\\extension"],"destination":"\/home\/seyfer\/www\/zend2-tutorial.me\/module\/users\/config\/..\/..\/..\/data\/uploads"}}" 

isuploaded passes, isvalid not.

what i'm doing wrong?

documentation this

zend_file_transfer has been deprecated in favor of using standard zf2 zend\form , zend\inputfilter features.

maybe it's mean, form need used file uploading in way?

upd 25.05.14

now i'm add form

class uploadjqueryform extends baseform {      public function __construct()     {         parent::__construct(__class__);         $this->setattribute('method', 'post');         $this->setattribute('enctype', 'multipart/form-data');          $this->init();     }      public function init()     {         $fileupload = new element\file('files');         $fileupload->setlabel("files");         $fileupload->setattribute('multiple', 'multiple');         $this->add($fileupload);          $button = new element\button('start');         $button->setattribute("type", 'submit');         $button->setvalue("start upload")->setlabel("start upload");         $this->add($button);          $button = new element\button('cancel');         $button->setattribute("type", 'reset');         $button->setvalue("cancel upload")->setlabel("cancel upload");         $this->add($button);          $button = new element\button('delete');         $button->setattribute("type", 'button');         $button->setvalue("delete")->setlabel("delete");         $this->add($button);          $checkbox = new element\checkbox('toggle');         $checkbox->setvalue("toggle")->setlabel("toggle");         $checkbox->setattribute("required", "");         $this->add($checkbox);     }  } 

use it

public function processjqueryaction()     {         $form      = new \users\form\uploadjqueryform();         $request   = $this->getrequest();         $response  = $this->getresponse();         $jsonmodel = new \zend\view\model\jsonmodel();          try {              if ($request->ispost()) {                  $data = array_merge_recursive(                         $this->getrequest()->getpost()->toarray(), $this->getrequest()->getfiles()->toarray()                 );  //                throw new \exception(json_encode("data " . serialize($data)));                  $form->setdata($data);                 if ($form->isvalid()) {                     $datas          = [];                     $datas['files'] = [];                     $uploadpath     = $this->getfileuploadlocation(); //                $uploadfiles    = $this->params()->fromfiles('files'); //                throw new \exception(json_encode("files " . serialize($_files)));                     // Сохранение выгруженного файла                     $adapter        = new \zend\file\transfer\adapter\http();                     $adapter->setdestination($uploadpath);                     $adapter->setvalidators(array(                         new \zend\validator\file\extension(array(                             'extension' => array('jpg', 'jpeg', 'png', 'rtf')                                 )                         ),                     ));                      if (!$adapter->isvalid()) {                         throw new \exception(json_encode("!isvalid " . implode(" ", $adapter->getmessages())));                     }                      $files = $adapter->getfileinfo(); //                throw new \exception(json_encode($files));                      foreach ($files $file => $info) { //                    throw new \exception(json_encode($info));                          $name = $adapter->getfilename($file);                          // file uploaded & valid                         if (!$adapter->isuploaded($file)) {                             throw new \exception(json_encode("!isuploaded") . implode(" ", $adapter->getmessages()));                             continue;                         }                          if (!$adapter->isvalid($file)) {                             throw new \exception(json_encode("!isvalid " . implode(" ", $adapter->getmessages())));                             continue;                         }                          // receive files user directory                         $check = $adapter->receive($file); // has on top                          if (!$check) {                             throw new \exception(json_encode("! receive" . implode(" ", $adapter->getmessages())));                         }                          /**                          * "name": "picture1.jpg",                           "size": 902604,                           "url": "http:\/\/example.org\/files\/picture1.jpg",                           "thumbnailurl": "http:\/\/example.org\/files\/thumbnail\/picture1.jpg",                           "deleteurl": "http:\/\/example.org\/files\/picture1.jpg",                           "deletetype": "delete"                          */                         $fileclass             = new stdclass();                         // stripped out image thumbnail our purpose, security reasons                         // add in here.                         $fileclass->name       = $name;                         $fileclass->size       = $adapter->getfilesize($name);                         $fileclass->type       = $adapter->getmimetype($name);                         $fileclass->deleteurl  = '/uploads/delete';                         $fileclass->deletetype = 'delete';                         //$fileclass->error = 'null';                         $fileclass->url        = '/';                          $datas['files'][] = $fileclass;                     }                      $response->getheaders()->addheaders(array(                         'pragma'        => 'no-cache',                         'cache-control' => 'private, no-cache',                         "content-type"  => 'application/json'                     ));                      return $response->setcontent(json_encode($datas));                 } else {                     throw new \exception(json_encode("!isvalid form" . serialize($form->getmessages())));                 }             }         } catch (\exception $e) {              return $response->setcontent(json_encode($e->getmessage()));         }          return $jsonmodel; 

and still error file '24866-fu-blyad-otvratitelno.jpg' not found

also tried inputfilter

class uploadjqueryfilter extends inputfilter implements inputfilterawareinterface {      public function __construct()     {         $this->getinputfilter();     }      public function getinputfilter()     {         $toggle = new input('toggle');         $toggle->setrequired(false);         $this->add($toggle);          $files = new \zend\inputfilter\fileinput('files');         $files->setrequired(true);         $files->getvalidatorchain()->attach(new validator\file\uploadfile);         $files->getfilterchain()->attach(new \zend\filter\file\renameupload(array(             'target'    => __dir__ . '/../../../../../../tmpuploads/tmp',             'randomize' => true,         )));         $this->add($files);          return $this;     }      public function setinputfilter(inputfilterinterface $inputfilter)     {         return false;     }  } 

and have same error.

i had problem too. wasting several hours before found problem. turn out it's because name attribute input tag cannot set 'files'.

so no:

<input id="files" type="file" name="files" data-url="/upload-action" /> 

changing name attribute string other files such file solve problem.

<input id="files" type="file" name="file" data-url="/upload-action" /> 

i see $_files had set name files. try changing that. make sure update reference made in controller too.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -