Das Folgende ist der Code (ich würde gerne fragen, wie man ihn ?ndert. Ich bin ein Anf?nger, vielen Dank im Voraus!):
<?php
Namespace AppHttpControllers;
verwenden Sie IlluminateHttpRequest;
AppHttpRequests verwenden;
class RequestController erweitert Controller
{
public function getFileupload(){
$postUrl='/laravelFirst/public/index.php/request/fileupload';
$csrf_field=csrf_field();
$html=<<<FILE
<form action="$postUrl" method="post" enctype="multipart/form-data">
$csrf_field
<input type="file" name="file"><br/>
<input type="submit" value="提交">
</form>
DATEI;
return $html;
}
public function postFileupload(Request $request){
if(!$request->hasFile('file')){
exit('上傳文件為空!');
}
$file=$request->file('file');
if(!$file->isValid()){
exit('上傳文件出錯(cuò)!');
}
$destPath = realpath(public_path('images'));
if(!file_exists($destPath)){
mkdir($destPath,0755,true);
}
$filename=$file->getClientOriginalName();
if(!$file->move($destPath,$filename)){
exit('保存文件失??!');
}
exit('文件上傳成功!');
}
}