PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 24, 2022

[FIXED] Image file is not created in folder

 January 24, 2022     laravel, laravel-5     No comments   

Issue

I need to store image in my folder with path project/public/uploads. My uploadImage function catch in parameter image, but file is not created.

public function uploadImage($image)
{
    $random = Str::random(10);
    if($image == null) { return; }
    $this->removeImage();
    $filename = $random . '.' . $image->extension();
    $image->storeAs('uploads', $filename);
    $this->image = $filename;
    $this->save();
}

dd($image) show this

Illuminate\Http\UploadedFile {#270 ▼
  -test: false
  -originalName: "korabl_more_zakat_luna_63381_1920x1080.jpg"
  -mimeType: "image/jpeg"
  -error: 0
  #hashName: null
  path: "/tmp"
  filename: "phpfJOzTp"
  basename: "phpfJOzTp"
  pathname: "/tmp/phpfJOzTp"
  extension: ""
  realPath: "/tmp/phpfJOzTp"
  aTime: 2020-02-07 18:51:11
  mTime: 2020-02-07 18:51:11
  cTime: 2020-02-07 18:51:11
  inode: 34603072
  size: 425567
  perms: 0100600
  owner: 1000
  group: 1000
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
}

Maybe it's has a meaning i'm using Linux OS, but my access right tuned for creating files in my project folder.


Solution

By default my congif file config/filesystems.php laravel save my images in storage/app/uploads, in config file need to change this

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => public_path(), // here was storage_path('app')
        ],

And now all images will save in public/uploads/image_name



Answered By - Malzeriy
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing