上传图片发现有错误请求帮助

controller如下

	if(isset($_POST['Suppliers']))


	{


		$model->attributes=$_POST['Suppliers'];


                    $model->port=CUploadedFile::getInstance($model,'port');


		if($model->save())


                            $model->port->saveAs('upfile');


			$this->redirect(array('view','id'=>$model->supplierid));


	}

view如下

             <?php echo $form->labelEx($model,'port'); ?>


	 <?php echo CHtml::activeFileField($model, 'port'); ?>


	<?php echo $form->error($model,'port'); ?>

我试着修改文件夹权限也不成功.

错误如下;

PHP Error

描述

move_uploaded_file(upfile) [<a href=‘function.move-uploaded-file’>function.move-uploaded-file</a>]: failed to open stream: Permission denied

源文件

D:\xampp\htdocs\vs\yii\framework\web\CUploadedFile.php(173)

00161: /**

00162: * Saves the uploaded file.

00163: * @param string the file path used to save the uploaded file

00164: * @param boolean whether to delete the temporary file after saving.

00165: * If true, you will not be able to save the uploaded file again in the current request.

00166: * @return boolean true whether the file is saved successfully

00167: */

00168: public function saveAs($file,$deleteTempFile=true)

00169: {

00170: if($this->_error==UPLOAD_ERR_OK)

00171: {

00172: if($deleteTempFile)

00173: return move_uploaded_file($this->_tempName,$file);

00174: else if(is_uploaded_file($this->_tempName))

00175: return copy($this->_tempName, $file);

00176: else

00177: return false;

00178: }

00179: else

00180: return false;

00181: }

00182:

00183: /**

00184: * @return string the original name of the file being uploaded

00185: */

堆栈追踪

#0 D:\xampp\htdocs\vs\yii\framework\web\CUploadedFile.php(173): move_uploaded_file()

#1 D:\xampp\htdocs\vs\yii\erp\protected\controllers\SuppliersController.php(82): CUploadedFile->saveAs()

#2 D:\xampp\htdocs\vs\yii\framework\web\actions\CInlineAction.php(32): SuppliersController->actionCreate()

#3 D:\xampp\htdocs\vs\yii\framework\web\CController.php(300): CInlineAction->run()

#4 D:\xampp\htdocs\vs\yii\framework\web\filters\CFilterChain.php(129): SuppliersController->runAction()

#5 D:\xampp\htdocs\vs\yii\framework\web\filters\CFilter.php(41): CFilterChain->run()

#6 D:\xampp\htdocs\vs\yii\framework\web\CController.php(999): CAccessControlFilter->filter()

#7 D:\xampp\htdocs\vs\yii\framework\web\filters\CInlineFilter.php(59): SuppliersController->filterAccessControl()

#8 D:\xampp\htdocs\vs\yii\framework\web\filters\CFilterChain.php(126): CInlineFilter->filter()

#9 D:\xampp\htdocs\vs\yii\framework\web\CController.php(283): CFilterChain->run()

#10 D:\xampp\htdocs\vs\yii\framework\web\CController.php(257): SuppliersController->runActionWithFilters()

#11 D:\xampp\htdocs\vs\yii\framework\web\CWebApplication.php(320): SuppliersController->run()

#12 D:\xampp\htdocs\vs\yii\framework\web\CWebApplication.php(120): CWebApplication->runController()

#13 D:\xampp\htdocs\vs\yii\framework\base\CApplication.php(135): CWebApplication->processRequest()

#14 D:\xampp\htdocs\vs\yii\erp\index.php(12): CWebApplication->run()

你在windows上试试看?

我用的是widows系统,xampp环境

我想 十有八九是你的upfile错了

必须要用物理地址,而不是URL地址。

:rolleyes:

$model->port->saveAs(‘upfile’);

你这个upfile算什么?文件夹还是文件?

正确应该是:$model->port->saveAs(’/xxx/xx/yyy.ext’);

这是唯一正确答案