2017-05-27 83 views
-1

我正在开发一个网站上传文件到public/images,但在我的共享主机我有不同的结构,所以上传不起作用。Laravel - 如何上传文件到不同的文件夹

我的结构是:

- css 
- images(I WANT TO UPLOAD TO THIS FOLDER) 
- fonts 
- js 
- laravel-code 
-.htaccess 

,如果我做呼应base_path()我得到/laravel-code,但我需要回来,我不知道怎么办。

如果使用public_path它会在laravel-code文件夹内创建一个/public/images,我不希望这样。

如何将图像保存在我的图像文件夹中?

谢谢

+0

最简单的将方法要使用/ storage /目录中的文件夹,然后创建符号链接到所需的公用文件夹(/ public/images)。 – manniL

+1

请检查这是否有帮助,https://stackoverflow.com/a/30790565/4874281 – manian

+0

可能重复的[Laravel - 如何更改上传文件路径](https://stackoverflow.com/questions/44218805/laravel-how -to-改变上传文件路径) –

回答

0

尝试:

base_path() . "/../images/" 
0

确定。试试吧

 public function upload(Request $request) 
     { 
      $file = $request->file('picture'); 
      $ext = $file->getClientOriginalExtension(); 
      $file->move("images/", "{$imageName}.{$ext}"); 
     } 
0

如果你的路径是公共/图像,然后,只要您可以使用目标路径为“图像/”,然后将文件移动到目的地是这样的:

/* check Request has file or not */ 
if($request->hasFile('file')){ 

    /* get File from Request */ 
    $file = $request->file('file'); 

    /* get File Extension */ 
    $extension = $file->getClientOriginalExtension(); 

    /* Your File Destination */ 
    $destination = 'images/'; 

    /* unique Name for file */ 
    $filename = uniqid() . '.' . $_extension; 

    /* finally move file to your destination */ 
    $file->move($destination, $filename); 
} 
相关问题