Laravel尝试将图像文件存储在3个不同的文件夹中。

huangapple go评论66阅读模式
英文:

Laravel trying to store image file in 3 different folder

问题

我尝试将图像存储在公共文件夹内的3个不同文件夹中,现在我能够存储在两个不同的文件夹中,但当我添加第三个文件夹路径时,它无法复制到第三个文件夹,请帮我解决这个问题。

我的两个文件夹复制工作代码

$input['student_photo'] = time() . '.' . $request->student_photo->getClientOriginalExtension();
$folder1 = public_path('public/path1/');
$path1 = $folder1 . $input['student_photo']; // 路径1
$request->student_photo->move($folder1, $input['student_photo']); // 图像保存在第一个文件夹
$path2 = public_path('public/path2/') . $input['student_photo']; // 路径2
\File::copy($path1, $path2);

我尝试复制第三个文件夹的代码,但不起作用

$input['student_photo'] = time() . '.' . $request->student_photo->getClientOriginalExtension();
$folder1 = public_path('public/path1/');
$path1 = $folder1 . $input['student_photo']; // 路径1
$request->student_photo->move($folder1, $input['student_photo']); // 图像保存在第一个文件夹
$path2 = public_path('public/path2/') . $input['student_photo']; // 路径2
$path3 = public_path('public/path3/') . $input['student_photo']; // 路径3
\File::copy($path1, $path2, $path3);

希望这可以帮助您解决问题。

英文:

I'm trying to store image in 3 different folder inside public folder now I'm able to store in two different folder but when I added 3rd folder path but it was not coping in 3rd folder help me to solve this.

my two folder copying Working code

$input['student_photo'] = time().'.'.$request->student_photo->getClientOriginalExtension();
    $folder1 = public_path('public/path1/');
    $path1 = $folder1 . $input['student_photo']; // path 1
    $request->student_photo->move($folder1, $input['student_photo']); // image saved in first folder
    $path2 = public_path('public/path2/') . $input['student_photo']; // path 2
    \File::copy($path1, $path2);

I tired this code for copy 3rd folder but not working

$input['student_photo'] = time().'.'.$request->student_photo->getClientOriginalExtension();
    $folder1 = public_path('public/path1/');
    $path1 = $folder1 . $input['student_photo']; // path 1
    $request->student_photo->move($folder1, $input['student_photo']); // image saved in first folder
    $path2 = public_path('public/path2/') . $input['student_photo']; // path 2
    $path3 = public_path('public/path3/') . $input['student_photo']; // path 3
    \File::copy($path1, $path2, $path3);

答案1

得分: 0

\File::copy($path1, $path2);
\File::copy($path1, $path3);

英文:
\File::copy($path1, $path2); 
\File::copy($path1, $path3);

huangapple
  • 本文由 发表于 2023年2月18日 21:38:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75493709.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定