Laravel 5.4 fopen():文件名不能为空
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45619248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.4 fopen(): Filename cannot be empty
提问by TheAngelM97
I want to upload image in laravel 5.4 Here's the code:
我想在laravel 5.4中上传图片这是代码:
if ($request->hasFile('image') && $request->image->isValid()) {
$image = $request->image;
$image_name = bcrypt($image->getClientOriginalName());
Storage::disk('public')->putFileAs('images', $image, $image_name . '.' . $image->getClientOriginalExtension());
$article->image($image_name);
}
in FilesystemAdapter.php (line 146)
在 FilesystemAdapter.php(第 146 行)
I checked the FileSystemAdapter.php and saw that the problem is in this line:
我检查了 FileSystemAdapter.php,发现问题出在这一行:
$stream = fopen($file->getRealPath(), 'r+');
When I var dump the $file variable it returns the correct info, but when I var_dump($file->getRealPath();
it says bool(false)
and I can't upload the image
当我对 $file 变量进行 var dump 时,它返回正确的信息,但是当我var_dump($file->getRealPath();
说bool(false)
我无法上传图像时
回答by Yevgeniy Afanasyev
We had this problem with Internet Information Services (IIS) for Windows? Server. And only thing needed was - permission for C:\Windows\temp because it is set as upload_tmp_dir in php.ini for php7.
我们在 Windows 的 Internet 信息服务 (IIS) 上遇到了这个问题?服务器。唯一需要的是 - C:\Windows\temp 的权限,因为它在 php7 的 php.ini 中设置为 upload_tmp_dir。
回答by saber tabatabaee yazdi
my case is :
我的情况是:
the target folder did not exist there. And i create it . so error gone.
目标文件夹在那里不存在。我创造了它。所以错误消失了。
laravel admin drive is defined here:
laravel 管理驱动器在此处定义:
Config/admin.php
配置/admin.php
You can define it in public folder, for example : upload folder in public.
您可以在公共文件夹中定义它,例如:公共文件夹中的上传。
my target folder (images) should be created in /uploads/ not in public
我的目标文件夹(图像)应该在 /uploads/ 中创建,而不是在公共
So I create images in upload and errors gone
所以我在上传时创建了图像并且错误消失了
回答by vinsa
My case with Laragon 4.0.12 on Windows 10.
我在 Windows 10 上使用 Laragon 4.0.12 的情况。
The problem was that upload_tmp_dir=... in my php.ini had not set needed permissions.
问题是我的 php.ini 中的 upload_tmp_dir=... 没有设置所需的权限。
If this setting is commented the value should be the default windows temp directory (C:\Windows\Temp you can check your permissions for it).
如果此设置被注释,则该值应该是默认的 Windows 临时目录(C:\Windows\Temp,您可以检查您的权限)。
The solution - I changed it to:
解决方案 - 我将其更改为:
upload_tmp_dir = "C:\Users\{my_user}\AppData\Local\Temp"
in order to avoid messing up with changing permissions.
以免弄乱更改权限。
Restart the server after the change to take effect.
修改生效后重启服务器。
Another settings in php.ini to consider:
php.ini 中要考虑的另一个设置:
upload_max_filesize =
max_file_uploads =
Also following php extensions are needed to be enabled: exif, gd2
还需要启用以下 php 扩展:exif、gd2