framework: [5.2] After move of uploaded file, missing temp file error.

This will give an error

public function addPost(ImageAddRequest $request) { if ($request->hasFile('image')){ $path = base_path()."/public/storage/pages/"; $image = $request->file('image'); $image->move($path, $image->getClientOriginalName()); $name = $request->name; } } any instance of request after move gives and error that the temp file can not be found.

found exactly the line that is causing issue.

laravel/framework/src/Illuminate/Http/UploadedFile.php Line 50

If I remove instanceof static it works fine.

The function is called from laravel/framework/src/Illuminate/Http/Request.php Line 419

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 75 (44 by maintainers)

Most upvoted comments

think resetting $_FILES before redirecting or Request::createFromGlobals() would work :

$_FILES = array(); //reset fileBag $request = Request::createFromGlobals();

@taylorotwell with Illuminate\Http\UploadedFile it works. Thanks!

I am using Laravel 7.8.1. I am trying to upload the image files. Its uploaded to public/images. But, when I try to retrieve the images it says that the image not found. BTW, I am using MacOS Catalina.

Any suggestion?? Thanks

I recently got same error on laravel 5.4 and php 5.6.4

(1/1) FileNotFoundException The file “/Applications/MAMP/tmp/php/phpRYjYHA” does not exist

in MimeTypeGuesser.php line 116

my controller code looked like this


foreach ( $request->file( 'files' ) as $file ) {
        $fileName = sha1( $file->getClientOriginalName() ) . "-" . $complaint->id . "." . $file->guessExtension();
        $file->move( public_path( 'complaint_media' ), $fileName );
	$cins = [
		'title'        => $file->getClientOriginalName(),
		'file'         => $fileName,
		'media_type'   => ComplaintMedia::getMediaType( $file->guessExtension() )
	];
						
        $comp_media = ComplaintMedia::create( $cins );
}

But then I moved all method calls on $file (i.e. getClientOriginalName() and guessExtension()) before $file->move() and it works now. My controller code now looks like this

foreach ( $request->file( 'files' ) as $file ) {
	$original_name = $file->getClientOriginalName();
	$extension = $file->guessExtension();
	$file_name = sha1($original_name)."-" .time().".".$extension;
						
	$file->move(public_path('complaint_media'), $file_name);
						
	$cins = [
		'title'        => $original_name,
		'file'         => $file_name,
		'media_type'   => ComplaintMedia::getMediaType($extension)
	];
						
	$comp_media = ComplaintMedia::create($cins);
}

@taylorotwell Hey! This issue is happening to me on Laravel 5.4, PHP 7, Ubuntu 16

After I move the uploaded file to a directory I make a call to a package class, but this package calls Request::createFromGlobals(); This is throwing the FileNotFoundException.

Example:


public function postStatus(Request $request)
{
    foreach ($request->allFiles() as $file) {
        $fileName = uniqid() . "_" . $file->getClientOriginalName();
        $file->move(storage_path("uploads/feeds"), $fileName);
    }

    // This line is throwing Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException
    // The file "/tmp/phpPQyWGk" does not exist
    $request = Request::createFromGlobals();

    dd($request->all());
}

// Help!

@vinkla when you do that “new UploadedFile” in your test is it an instance of Illuminate\Http\UploadedFile or a Symfony version?