1

I tried to upload image on my public folder but i constantl getting error like this

The "C:\xampp\tmp\phpCE7B.tmp" file does not exist or is not readable.

Her is my code that i tried so far

public function create(Register $request)
    {
        //Registering Students
        $student=new Student;
        $student->name = $request->input('name');
        $student->username = $request->input('username');
        $student->email = $request->input('email');
        $student->password = bcrypt($request->input('password'));
        $student->gender = $request->input('gender');
        $student->phone = $request->input('phone');
        if ($request->hasFile('image')) {
            $file=$request->File('image');
            $ext=$student->username. "." .$file->clientExtension();
            $path = public_path(). '/images/';
            $file->move($path,$ext);
            $student->image = $ext;
        }
        $student->save();
}

it saved my info with image in database but after storing gives me the error.Please help me to solve this

"UPDATE"

I dont Know what is happening to me, but now its working autometically

4
  • 2
    Your code seems ok, this sounds like a server config problem. Make sure you don't run out of HD space, server has access to C:\Xampp\tmp, also check if the phpCE7B.tmp exists there. Also try using $request->storeAs(...). Commented Nov 5, 2019 at 17:53
  • i dont have the HD space problem and yes there is no phpCE7B file is exists. And whow to use storeAs image to save it in pubic folder i dont kno can ou tell me how Commented Nov 5, 2019 at 17:57
  • just replace ->move with ->storeAs. If that doesn't help, try reinstalling Xampp or move to some other tool that works. Commented Nov 5, 2019 at 18:00
  • also check the folder permissions. Commented Nov 5, 2019 at 18:47

3 Answers 3

2

I have the same problem when i'm trying to upload image to public path. I solved the problem by defining a file system disk in config (filesystems) like that:

'YourDiskName' => [
    'driver' => 'local',
    'root'   => public_path(),
],

then you can upload images to this path by using StoreAs method:

$file = $file->storeAs(YourPathInPublic, YourFileName, [
    'disk' => 'YourDiskName'
]);
Sign up to request clarification or add additional context in comments.

Comments

0
// Get Form Image
             $image = $request->file('image');
            $slug = str_slug($request->name);
            if (isset($image))
            {
                $currentDate = Carbon::now()->toDateString();
                $imagename = $slug.'-'.$currentDate.'-'. uniqid() .'.'. $image->getClientOriginalExtension();
                if (!file_exists('storage/uploads/post'))
                {
                    mkdir('storage/uploads/post',0777,true);
                }
                $image->move('storage/uploads/post',$imagename);
            }else{
                $imagename = "default.png";
            }
//getting coding


 public function index(){

    return view('admin.post.index',compact('posts'));
    }
// show code

<div class="body">
  <img class="img-responsive img-thumbnail" src="{{ asset('storage/uploads/post/'.$post->image) }}" >
    </div>

Comments

0

I also had the same issue when I use public_path()

Try something like this rather than using public_path. Actually there is nothing wrong with your code. But this happens most of the time due to permission levels. As others said you can try reinstalling Xampp or just try this.

if ($request->hasFile('image')) {
    $file = $request->File('image');
    $ext = $student->username.".".$file->clientExtension();

    $ext->save('your_public_path/'.$ext);

    //$path = public_path().'/images/';
    //$file->move($path,$ext);
    $student->image = $ext;
}

Example code from one of my project for your info

$image = $request->file('uploadUserAvatar');
$fileName = time().'.'.request()->uploadUserAvatar->getClientOriginalExtension() ;
$image_resize = Image::make($image->getRealPath());
$image_resize->resize(300,300);
$image_resize->save(('assets/img/user_avatars/'.$fileName));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.