我试图让我的用户上传.pdf文件,但在调用putFile方法或putFileAs方法时,我收到以下错误:
在null中调用成员函数hashName() \厂商\ laravel \框架\ SRC \照亮\文件系统\ FilesystemAdapter.php:146
检查putFile方法的$file
属性返回null。但是,当我给出给定的参数时,它返回(因为它看起来像)一个普通的文件。
它在whoops中返回以下publication_file
array:5 [▼
"name" => "users-tragos.pdf"
"type" => "application/pdf"
"tmp_name" => "C:\xampp\tmp\phpAB1F.tmp"
"error" => 0
"size" => 205603
]
我的控制器代码是:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Carbon\Carbon;
use App\Http\Controllers\Controller;
use App\publication;
use App\User;
class publicationsController extends Controller
{
public function store(Request $request){
$this->validate($request, [
'title' => 'required',
'author' => 'required',
'publication_date' => 'required|date_format:m/Y'
]);
if($request->filled("publication_url")){
$this->validate($request, [
'publication_url' => 'url'
]);
}
if($request->filled("publication_file")){
$this->validate($request, [
'publication_file' => 'file|mimes:pdf|max:10000'
]);
}
$publication_date = carbon::createFromFormat('m/Y', request("publication_date"))->format('Y-m-d');
if($request->hasFile('publication_file')){
if($request->file('publication_file')->isValid()){
$path = Storage::putFile('publications', $request->file('publication_file'));
}
}
}
我的表单代码是:
<form method="POST" action="/publications" id="form_table" enctype="multipart/form-data">
{{ csrf_field() }}
<table>
<tr><td><label for="title">Title</label></td><td><input type="text" name="title" id="title" required autofocus /></td></tr>
<tr><td><label for="title">Author</label></td><td><input type="text" name="author" id="author" required /></td></tr>
<tr><td><label for="publication_date">Publication Date</label></td><td>
<input type="text" name="publication_date" id="publication_date" required placeholder="mm/yyyy"/></td></tr>
<tr><td colspan="2"><label for="content">Content</label><br /><br />
<textarea name="body" id="content"></textarea></td></tr>
<tr><td><label for="publication_file">Upload .pdf file</label></td><td>
<input type="file" id="publication_file" name="publication_file" accept="application/pdf" /></td></tr>
<tr><td><label for="publication_url">Link to file</label></td><td><input type="text" id="publication_url" name="publication_url" /></td></tr>
<tr><td><button type="submit" value="submit"/>submit</button></td></tr>
</table>
</form>
有谁知道如何解决这个问题?我正在使用Laravel 5.5