6
Nawet jeśli wybiorę 2 lub więcej obrazów, tylko jeden zostanie przesłany.Jak przesłać wiele plików za pomocą Zend Framework?
Mam prosty formularz:
<form action="/images/thumbs" method="post" enctype="multipart/form-data">
<input name="file[]" id="file" type="file" multiple="" />
<input type="submit" name="upload_images" value="Upload Images">
</form>
potem w moim kontrolera:
public function thumbsAction()
{
$request = $this->getRequest();
if ($request->isPost()) {
if (isset($_POST['upload_images'])) {
$names = $_FILES['file']['name'];
// the names will be an array of names
foreach($names as $name){
$path = APPLICATION_PATH.'/../public/img/'.$name;
echo $path; // will return all the paths of all the images that i selected
$uploaded = Application_Model_Functions::upload($path);
echo $uploaded; // will return true as many times as i select pictures, though only one file gets uploaded
}
}
}
}
oraz metodę upload
:
public static function upload($path)
{
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addFilter('Rename', array(
'target' => $path,
'overwrite' => true
));
try {
$upload->receive();
return true;
} catch (Zend_File_Transfer_Exception $e) {
echo $e->message();
}
}
Jakieś pomysły dlaczego dostać tylko jeden plik przesłany ?
Myślę, że masz problem z tym kodem. '$ apt' nie jest zdefiniowane. Czy chodziło Ci o '$ upload'? –
zmieniono .. Przepraszam za to .. – Dinesh
Dzięki, to mi się udało dla Zf2. –