Php 在symfony 1.4中上载和解压缩zip文件
我想在symfony中上载zip文件,但未能上载 当我上传文本或pdf或excel文件,图像或单个文件,然后它是上传罚款 但当我试图上传zip文件时,它并没有返回任何信息,也并没有错误日志,只有一个空白页面 我是我的表单,我有以下代码 但此代码仅适用于单个文件,而不适用于zip文件Php 在symfony 1.4中上载和解压缩zip文件,php,symfony-1.4,orangehrm,Php,Symfony 1.4,Orangehrm,我想在symfony中上载zip文件,但未能上载 当我上传文本或pdf或excel文件,图像或单个文件,然后它是上传罚款 但当我试图上传zip文件时,它并没有返回任何信息,也并没有错误日志,只有一个空白页面 我是我的表单,我有以下代码 但此代码仅适用于单个文件,而不适用于zip文件 我想上载和解压缩zip文件。您的存档文件的大小是多少?大约60 MB,将来可能会超过。问题是,当我上载zip文件时,我无法获取zip文件名,文件仍保留在该zip文件夹中。你知道如何在symfony 1.4中上传和解
我想上载和解压缩zip文件。您的存档文件的大小是多少?大约60 MB,将来可能会超过。问题是,当我上载zip文件时,我无法获取zip文件名,文件仍保留在该zip文件夹中。你知道如何在symfony 1.4中上传和解压缩zip文件吗?正如我读过的symfony文档,但是只有文件上传示例,不包含任何zip上传示例。您是否检查过php配置是否允许大小为60mb的文件上传?这就是为什么symfony没有向您显示任何内容,因为上传失败。试着再试试。也许,尝试使用更少的zip文件,比如5moFirst,如果它接受来自文件上载控制的zip文件,那么问题是允许的上载文件大小。但是当我上载zip文件时,我无法获取该zip文件名并提取其内容。当我上传pdf、word、excel、图像时,我可以很容易地获得文件名。所以我的问题是,为什么文件上传conterol无法检测到zip文件,我的表单中是否缺少任何内容?
class UploadSalaryForm extends BaseForm {
public function configure() {
// Note: Widget names were kept from old non-symfony version
$var = 'salary';
$this->setWidgets(array(
'EmpID' => new sfWidgetFormInputHidden(),
'seqNO' => new sfWidgetFormInputHidden(),
'MAX_FILE_SIZE' => new sfWidgetFormInputHidden(),
'ufile' => new sfWidgetFormInputFile(),
'txtAttDesc' => new sfWidgetFormInputText(),
'screen' => new sfWidgetFormInputHidden(),
'commentOnly' => new sfWidgetFormInputHidden(),
));
$this->setValidators(array(
'EmpID' => new sfValidatorNumber(array('required' => true, 'min'=> 0)),
'seqNO' => new sfValidatorNumber(array('required' => false, 'min'=> 0)),
'MAX_FILE_SIZE' => new sfValidatorNumber(array('required' => true)),
'ufile' => new sfValidatorFile(array('required' => false)),
//'ufile', new sfValidatorFileZip(array('required' => false)),
'txtAttDesc' => new sfValidatorString(array('required' => false)),
'screen' => new sfValidatorString(array('required' => true,'max_length' => 50)),
'commentOnly' => new sfValidatorString(array('required' => false)),
));
// set up your post validator method
$this->validatorSchema->setPostValidator(
new sfValidatorCallback(array(
'callback' => array($this, 'postValidate')
))
);
}
public function postValidate($validator, $values) {
// If seqNo given, ufile should not be given.
// If seqNo not given and commentsonly was clicked, ufile should be given
$attachId = $values['seqNO'];
$file = $values['ufile'];
$commentOnly = $this->getValue('commentOnly') == "1";
if (empty($attachId) && empty($file)) {
$message = sfContext::getInstance()->getI18N()->__('Upload file missing');
$error = new sfValidatorError($validator, $message);
throw new sfValidatorErrorSchema($validator, array('' => $error));
} else if (!empty($attachId) && $commentOnly && !empty($file)) {
$message = sfContext::getInstance()->getI18N()->__('Invalid input');
$error = new sfValidatorError($validator, $message);
throw new sfValidatorErrorSchema($validator, array('' => $error));
}
return $values;
}
/**
* Save employee contract
*/
public function save() {
$empNumber = $this->getValue('EmpID');
$attachId = $this->getValue('seqNO');
$empAttachment = false;
if (empty($attachId)) {
$q = Doctrine_Query::create()
->select('MAX(a.attach_id)')
->from('EmployeeAttachment a')
->where('a.emp_number = ?', $empNumber);
$result = $q->execute(array(), Doctrine::HYDRATE_ARRAY);
if (count($result) != 1) {
throw new PIMServiceException('MAX(a.attach_id) failed.');
}
$attachId = is_null($result[0]['MAX']) ? 1 : $result[0]['MAX'] + 1;
} else {
$q = Doctrine_Query::create()
->select('a.emp_number, a.attach_id')
->from('EmployeeAttachment a')
->where('a.emp_number = ?', $empNumber)
->andWhere('a.attach_id = ?', $attachId);
$result = $q->execute();
if ($result->count() == 1) {
$empAttachment = $result[0];
} else {
throw new PIMServiceException('Invalid attachment');
}
}
//
// New file upload
//
$newFile = false;
if ($empAttachment === false) {
$empAttachment = new EmployeeAttachment();
$empAttachment->emp_number = $empNumber;
$empAttachment->attach_id = $attachId;
$newFile = true;
}
$commentOnly = $this->getValue('commentOnly');
if ($newFile || ($commentOnly == '0')) {
$file = $this->getValue('ufile');
echo "file==".$file;
$tempName = $file->getTempName();
$empAttachment->size = $file->getSize();
$empAttachment->filename = $file->getOriginalName();
$empAttachment->attachment = file_get_contents($tempName);;
$empAttachment->file_type = $file->getType();
$empAttachment->screen = $this->getValue('screen');
$empAttachment->attached_by = $this->getOption('loggedInUser');
$empAttachment->attached_by_name = $this->getOption('loggedInUserName');
// emp_id and name
}
$empAttachment->description = $this->getValue('txtAttDesc');
$empAttachment->save();
}
}