
以下是代码(想问一下该如何修改。自己小白一个,先提前谢谢大家!):
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class RequestController extends Controller
{
public function getFileupload(){
$postUrl='/laravelFirst/public/index.php/request/fileupload';
$csrf_field=csrf_field();
$html=<<
$csrf_field
FILE;
return $html;
}
public function postFileupload(Request $request){
if(!$request->hasFile('file')){
exit('上传文件为空!');
}
$file=$request->file('file');
if(!$file->isValid()){
exit('上传文件出错!');
}
$destPath = realpath(public_path('images'));
if(!file_exists($destPath)){
mkdir($destPath,0755,true);
}
$filename=$file->getClientOriginalName();
if(!$file->move($destPath,$filename)){
exit('保存文件失败!');
}
exit('文件上传成功!');
}
}
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你打印那个destPath看看
laravel上传文件还是使用
Storage这个Facade吧,他可以自己处理文件夹创建之类的问题