1.test.php
‘/test/upload/'改成你相应的地址。
2.TestController.php
public function actionUpload()
{
$dir = isset($_REQUEST['dir']) ? $_REQUEST['dir'] : '';
$image = CUploadedFile::getInstanceByName('file');
$dir=Yii::getPathOfAlias('webroot').'/images/'.$dir.'/';
//上传目录
if (!is_dir($dir)) {
mkdir($dir);
//目录不存在则创建
}
$name = $dir.$image->name;
//文件名绝对路径
$status = $image->saveAs($name,true);
//保存文件
if ($status) {
echo 'success';
}else {
echo 'fail';
}
}
3. 测试
访问http://www.ttlsa.com/test/test,上传你的文件即可。如果出现succes说明成功了。
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn