我正在尝试使用zend上传文件,但似乎无法理解为什么这段代码不能工作。它没有出现在我指定的目录中。任何帮助都会很好。谢谢!
public function uploadFormAction()
{
$form = new UploadForm('upload-form');
$tempFile = null;
$prg = $this->fileprg($form);
if ($prg instanceof Response) {
return $prg; // Return PRG redirect response
} elseif (is_array($prg)) {
if ($form->isValid()) {
$data = $form->getData();
// echo $data['image-file']['name'];
$tmp = $data['image-file']['tmp_name'];
$name = $data['image-file']['name'];
$uploads_dir = '//Applications/MAMP/htdocs/';
move_uploaded_file($tmp, "$uploads_dir");
echo($name);
echo($uploads_dir);
// Form is valid, save the form!
// return $this->redirect()->toRoute('uploadForm/success');
} else {
// Form not valid, but file uploads might be valid...
// Get the temporary file information to show the user in the view
$fileErrors = $form->get('image-file')->getMessages();
if (empty($fileErrors)) {
$tempFile = $form->get('image-file')->getValue();
}
}
}
return array(
'form' => $form,
'tempFile' => $tempFile,
);
}HTML表单-上传-form.html
$title = 'Upload';
$this->headTitle($title);
?>
<h1><?php echo $this->escapeHtml($title); ?></h1>
<?php
$form->setAttribute('action', $this->url('album', array('action' => 'uploadForm')));
$form->prepare();?>
<?php echo $this->form()->openTag($form); ?>
<div class="form-element">
<?php $fileElement = $form->get('image-file'); ?>
<?php echo $this->formLabel($fileElement); ?>
<?php echo $this->formFile($fileElement); ?>
<?php echo $this->formElementErrors($fileElement); ?>
</div>
<button>Submit</button>
<?php echo $this->form()->closeTag(); ?>发布于 2015-04-12 15:34:17
$form->setAttribute(“封装类型”,“多部分/表单数据”);
发布于 2015-04-13 18:16:02
您的目标目录路径似乎不正确。
$uploads_dir = '//Applications/MAMP/htdocs/';这应该是这样的:
$uploads_dir=realpath(APPLICATION_PATH) . "/../public/Your directory path您可以使用is_dir function检查您的路径。
https://stackoverflow.com/questions/29584995
复制相似问题