php - CakePHP multiple file upload field only uploading one image -


i trying upload files using multiple upload file field. post information gets sent correctly , looks this:

array (     [uploads] => array         (             [photos] => array                 (                     [0] => array                         (                             [name] => image - copy - copy.jpg                             [type] => image/jpeg                             [tmp_name] => /tmp/phpalamwt                             [error] => 0                             [size] => 60892                         )                      [1] => array                         (                             [name] => image - copy.jpg                             [type] => image/jpeg                             [tmp_name] => /tmp/phpoigtta                             [error] => 0                             [size] => 60892                         )                      [2] => array                         (                             [name] => image.jpg                             [type] => image/jpeg                             [tmp_name] => /tmp/phpertogu                             [error] => 0                             [size] => 60892                         )                  ) 

and loop through , insert each 1 database, upload them using id database, this:

// upload photos if (!empty($this->request->data['uploads']['photos'][0]['tmp_name'])){      foreach($this->request->data['uploads']['photos']as $photo){          $property_id = $this->request->data['property']['id'];         $file_name = $photo['name'];         $file_size = $photo['size'];         $file_ext = pathinfo($photo['name'], pathinfo_extension);          // save db         $this->property->propertyimage->save(array(             'propertyimage' => array("live"=>1, 'number'=>99, "type"=>'l', "filetype"=>$file_ext, "propertyid"=>$property_id, 'source'=>$file_name, 'size=>'.$file_size)         ));          // upload         $id = $this->property->propertyimage->getlastinsertid();         $path = intval($id/1000) . '/' . $id . '.' . $file_ext;         move_uploaded_file($photo['tmp_name'], $_server['document_root'].'/imgp/f/'.$path);      } } 

but 1 image gets put database , uploaded each time, cant work out why isn't working right.

any ideas? thanks.

before line call save()

$this->property->propertyimage->save(...) 

call

$this->property->propertyimage->create(); 

to tell model write new record instead of continue work saved one.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -