2017-07-07 5 views
0

2つの異なる場所にファイルをアップロードしようとしています。塗りは/2x/とadn /3x/です。それは3倍にファイルをアップロードしますが2倍にしないと、このエラーがスローされます。ここではLaravel:不明なエラーのためファイルがアップロードされていません

The file was not uploaded due to an unknown error

は私がやっているものです:

$photo = $request->file('photo'); 

       if (isset($photo)) { 
        if ($photo != null || $photo != '') { 

         $imageSize = getimagesize($photo); 
         $resolution = $imageSize[0] . 'x' . $imageSize[1]; 

         if ($resolution == '300x300' || $resolution == '450x450') { 

          if (!file_exists(base_path('uploads/custom_avatar'))) { 
           mkdir(base_path('uploads/custom_avatar'), 0777, true); 
          } 

          $resolution = "3x"; 

          $uploadPath = base_path('uploads/custom_avatar/' . $resolution . '/'); 

          $otherImageResolution = '2x'; 
          $otherImagePath = base_path('uploads/custom_avatar/' . $otherImageResolution . '/'); 
//       echo $otherImagePath;exit; 
          // saving image 
          $fileName = $child->id . '_' . time() . '.png'; 

          $photo->move($uploadPath, $fileName); 
          $photo->move($otherImagePath, $fileName); 

          // creating records 
          $childImage = Images::addPhoto($child->id, $fileName, $resolution); 
          $otherImage = Images::addPhoto($child->id, $fileName, $otherImageResolution); 

          if ($childImage && $otherImage) { 
           $result = Child::createChildResponseData($child); 
           \Log::info('Child avatar added Successfully' . json_encode($childImage)); 
           return response()->json([ 
            'status' => $this->SUCCESS, 
            'response' => $result, 
           ], $this->SUCCESS); 
          } 

任意のヘルプ?

+0

移動したり、複数の場所への要求からファイルをコピーします[ stackoverflowの質問](https://stackoverflow.com/questions/38979386/move-or-copy-a-file-from-the-request-to-multiple-locations) –

+0

ありがとう@SurenderSinghRawat、それは働いた。 – Saani

答えて

1

あなたはこれを試すことができます。

$request->file('photo')->move($destination_path, $file_name); 

は、必要に応じて、パスとファイル名の間DIRECTORY_SEPARATORを追加し、 コピーファイルという新しい場所で

copy($destination_path.$file_name, $new_path.$new_file_name); 
関連する問題