shahr's avatar
Level 10

The file "9.jpg" was not uploaded due to an unknown error.

I have a multiple image. When I upload multiple image. I get this error.

The file "9.jpg" was not uploaded due to an unknown error.

my blade

<form action="{{ route('design-studios.store') }}" method="post" enctype="multipart/form-data">
    @csrf
    <div class="form-group">
        <label for="title">Title</label>
        <input type="text" class="form-control" id="title" name="title" value="{{ old('title') }}">
    </div>
   //......
    <div class="form-group">
        <fieldset class="border p-3">
            <legend>Slideshow</legend>
            <div class="form-group">
                <label for="sliders">Image</label>
                <input id="sliders" name="sliders[]" type="file" multiple class="form-control">
            </div>
        </fieldset>
    </div>
</form>

My Controller.

public function store(Request $request)
{
    $design_studio = new DesignStudio;
    $design_studio->user_id = 1;
    $design_studio->title = $request->title;
    $design_studio->lang = $request->lang;
    $design_studio->body = $request->body;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/design-studio'), $filename);
        $design_studio->image = $request->file('image')->getClientOriginalName();
    }
    if ($sliders = $request->file('sliders')) {
        foreach ($sliders as $slider) {
            $image = $request->file('sliders');
            $filename = $image->getClientOriginalName();
            $image->move(public_path('images/design-studio'), $filename);
            $design_studio->image = $request->file('sliders')->getClientOriginalName();
        }
    }
    $design_studio->save();
    $design_studio->categories()->attach($request->category);
    return redirect()->route('design-studios.index');
}

My Model

protected $casts = [
    'sliders' => array()
];

I get this ervror.

The file "9.jpg" was not uploaded due to an unknown error.

0 likes
15 replies
shahr's avatar
Level 10

The file "9.jpg" was not uploaded due to an unknown error.

automica's avatar

@oxbir does that directory exist in your storage/public folder?

you should be able to see more of the errors if you look in Laravel log within storage/logs

shahr's avatar
Level 10

I don't see any an errors.

did not error

automica's avatar

@oxbir if that's erroring, it should be writing to the log. check file permissions on the logs directory.

Do you have any images in your image folder?

shahr's avatar
Level 10

@automica

Yes I have folders C:\xampp\htdocs\tehran\khaneyeax\public\images\design-studio But It did not work, AHHH.

I see this error again.

The file "9.jpg" was not uploaded due to an unknown error.
shahr's avatar
Level 10

Is there anyone who can answer my question?

automica's avatar

@oxbir you say you are using a component to upload multiple files.

  1. is it placing any in that directory?
  2. have you tried other files other than the one you are trying to upload?
  3. have you managed to upload 8 previous ones?
  4. have you changed any code since you got previous files to upload?

I still think you have permissions issues on your directories. do these have write permission? if in doubt chmod 777 (in dev) Your app may not also be able to write to tmp directory so ensure you have enabled permissions there too.

automica's avatar

@oxbir did you work this out yet? would be interested to know how you'd solved it.

Snapey's avatar

Its a simple coding error in this loop

 foreach ($sliders as $slider) {
            $image = $request->file('sliders');
            $filename = $image->getClientOriginalName();
            $image->move(public_path('images/design-studio'), $filename);
            $design_studio->image = $request->file('sliders')->getClientOriginalName();
        }

iterating over $sliders as $slider but then references sliders multiple places within the loop.

1 like
automica's avatar

which should then be:

 foreach ($sliders as $image) {
  	   $filename = $image->getClientOriginalName();
           $image->move(public_path('images/design-studio'), $filename);
           $design_studio->image = $filename;
        }
rahma-AL-lnassar's avatar

i have same error "The file was not uploaded due to an unknown error in laravel" can you help me plase? this is my code:

rahma-AL-lnassar's avatar

$product = Product::findOrFail($id); $candidate = [ 'name_ar' => $request->name_ar, 'name_en' => $request->name_en, 'text_desc_ar' => $request->text_desc_ar, 'text_desc_en' => $request->text_desc_en, 'price' => $request->price, 'offer' => $request->offer, 'ratio' => $request->ratio, 'end_at' => $request->end_at, 'subcat_id' => $request->subcat_id, 'order' => $request->order, 'new_price' => $request->new_price, 'software' => $request->software, 'software2' => $request->software2, 'software3' => $request->software3 ]; $subcat = DB::table('subcats')->where('id', $request->subcat_id)->first(); $file = $request->file('pdf'); $fileName = $file->getClientOriginalName(); if ($request->file('pdf') != '') { $file = $request->file('pdf'); $fileName = $file->getClientOriginalName();

    if ($subcat->name_en == '4K') {

      $file->move(base_path('en/files/product1'),  $fileName);
    }
    if ($subcat->name_en == 'FHD') {
      $file->move(base_path('en/files/product2'), $fileName);
    }
    if ($subcat->name_en == 'HD') {
      $file->move(base_path('en/files/product3'), $fileName);
    } else {
      $file->move(base_path('en/files/user manual'), $fileName);
    }
  }

  if ($request->file('pdf')  == '') {
    $product->file = '';
  }
  $file1 = $request->file('desc_ar');
  if ($request->file('desc_ar') != '') {
    $file1 = $request->file('desc_ar');

    $fileData = $this->uploads($file, 'uploads/products/');

    $file1 = $fileData['fileName'];
  }
  $file2 = $request->file('desc_en');
  if ($request->file('desc_en') != '') {
    $file2 = $request->file('desc_en');

    $fileData = $this->uploads($file, 'uploads/products/');

    $file2 = $fileData['fileName'];
  }
  $data1 = array_merge($candidate, ['file' => $fileName, 'desc_ar' => $file1, 'desc_en' => $file2]);
  $product->update($data1);
Snapey's avatar

@rahma-AL-lnassar start your own question, and format your code blocks correctly.

Please or to participate in this conversation.