我使用以下方法上传和转换PDF文件使用图像魔术。创建方法正在工作,但没有将图像上载到相应的目录中。
public function actionCreate()
{
$model=new Alerts;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Alerts']))
{
$model->attributes=$_POST['Alerts'];
$model->infoFile=CUploadedFile::getInstance($model,'infoFile');
$pdf_file = $model->infoFile->name;
$save_to = $model->getUploadPath()."sample.jpg";
if($model->save()){
exec('convert "'.$pdf_file.'" -colorspace RGB -resize 800 "'.$save_to.'"', $output, $return_var);
}
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
你能建议是什么问题吗?
我可以保证webserver有对$model->getUploadPath()
(即Yii::getPathofAlias('webroot').'/uploads/';
)的写权限,并且Image Magic在webserver中已正确安装和配置。
出于安全原因,大多数主机禁用了exec功能。
$uploadedFile->saveAs($model->getUploadPath()."sample.jpg");
只是为了验证Yii保存文件的方式是否有效。如果这有效,您应该查看:
- 在您的服务器上是否允许执行
- Imagick是否正确安装/配置
我的Ghostscript安装有一些问题。所以我重新安装了ghostscript,现在一切都开始工作了。感谢大家对物质的研究。