We help IT Professionals succeed at work.

What is "SplFileInfo::getSize(): stat failed for C:\wamp64\tmp\phpA213.tmp?"

Bruce Gust
Bruce Gust asked
on
Here's my code:

public function store(VideoRequest $request)
    {
        //
		$validated = $request->validated();
		$movie = new Video;
		
		if($request->hasFile('thumbnail')) {
			$file = $request->file('thumbnail');
			$thumbnail = $file->getClientOriginalName();
			$movie->thumbnail=$thumbnail;
			$file->move('assets/img', $thumbnail);
		}
			
		$movie->title=$validated['title'];
		$movie->description=$validated['description'];
		$movie->filename=$validated['filename'];
		$success='Video was successfully created!';
		
		if($movie->save()) {
			return View::make('/admin/displayVideo')
			->with('film', $movie)
			->with('newVideo', 'Here\'s the video you just created!');
		}
    }

Open in new window


It works!

All of the text, filenames etc are uploaded to the database and the thumbnail is accurately loaded into the appropriate directory..

But...

I get this error:

SplFileInfo::getSize(): stat failed for C:\wamp64\tmp\phpA213.tmp
(1/1) RuntimeException
SplFileInfo::getSize(): stat failed for C:\wamp64\tmp\phpA213.tmp

in RequestContext.php line 52
at SplFileInfo->getSize()
in RequestContext.php line 52
at RequestContext->Facade\FlareClient\Context\{closure}(object(UploadedFile))
at array_map(object(Closure), array('thumbnail' => object(UploadedFile)))
in RequestContext.php line 41
at RequestContext->mapFiles(array('thumbnail' => object(UploadedFile)))
in RequestContext.php line 36
at RequestContext->getFiles()
in RequestContext.php line 95
at RequestContext->getRequestData()
in RequestContext.php line 103
at RequestContext->toArray()
in LaravelRequestContext.php line 64
at LaravelRequestContext->toArray()
in Report.php line 211
at Report->allContext()
in AnonymizeIp.php line 11
at AnonymizeIp->handle(object(Report), object(Closure))
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Report))
in AddGlows.php line 24
at AddGlows->handle(object(Report), object(Closure))
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Report))
in Pipeline.php line 105
at Pipeline->then(object(Closure))
in Flare.php line 203
at Flare->applyMiddlewareToReport(object(Report))
in Flare.php line 179
at Flare->createReport(object(ViewException))
in ErrorPageHandler.php line 39
at ErrorPageHandler->handle(object(ViewException))
in IgnitionWhoopsHandler.php line 25
at IgnitionWhoopsHandler->handle(object(ViewException))
in Run.php line 321
at Run->handleException(object(ViewException))
in Handler.php line 345
at Handler->renderExceptionWithWhoops(object(ViewException))
in Handler.php line 324
at Handler->renderExceptionContent(object(ViewException))
in Handler.php line 308
at Handler->convertExceptionToResponse(object(ViewException))
in Handler.php line 287
at Handler->prepareResponse(object(Request), object(ViewException))
in Handler.php line 192
at Handler->render(object(Request), object(ViewException))
in Handler.php line 49
at Handler->render(object(Request), object(ViewException))
in Pipeline.php line 51
at Pipeline->handleException(object(Request), object(ViewException))
in Pipeline.php line 132
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in CheckRole.php line 23
at CheckRole->handle(object(Request), object(Closure), ' admin')
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure))
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in VerifyCsrfToken.php line 76
at VerifyCsrfToken->handle(object(Request), object(Closure))
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in StartSession.php line 56
at StartSession->handle(object(Request), object(Closure))
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in EncryptCookies.php line 66
at EncryptCookies->handle(object(Request), object(Closure))
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php line 105
at Pipeline->then(object(Closure))
in Router.php line 682
at Router->runRouteWithinStack(object(Route), object(Request))
in Router.php line 657
at Router->runRoute(object(Request), object(Route))
in Router.php line 623
at Router->dispatchToRoute(object(Request))
in Router.php line 612
at Router->dispatch(object(Request))
in Kernel.php line 176
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
in Pipeline.php line 130
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in TransformsRequest.php line 21
at TransformsRequest->handle(object(Request), object(Closure))
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in TransformsRequest.php line 21
at TransformsRequest->handle(object(Request), object(Closure))
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in ValidatePostSize.php line 27
at ValidatePostSize->handle(object(Request), object(Closure))
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in CheckForMaintenanceMode.php line 62
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in TrustProxies.php line 57
at TrustProxies->handle(object(Request), object(Closure))
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php line 105
at Pipeline->then(object(Closure))
in Kernel.php line 151
at Kernel->sendRequestThroughRouter(object(Request))
in Kernel.php line 116
at Kernel->handle(object(Request))
in index.php line 55

Open in new window


If I refresh the page, the error goes away and I get an alert that that the filenam is already taken. And that's because everything was added and uploaded correctly..

So why am I getting this error?

Here's my Request file:

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class VideoRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //
			'title' => 'required', 
			'filename' =>'required | unique:videos',
			'description' => 'required'
        ];
    }
	
	public function messages()
    {
        return [
            'title is.required' => 'title is required!',
            'filename is.required' => 'don\'t forget to include your video file!',
			'descirption is.required' => 'be sure to include the description'
        ];
    }
}

Open in new window


What do yo uthink?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
Hey Bruce,

Not entirely sure what's going on, but that error indicates that somewhere in your code, it's trying to get the size of the file that's been uploaded (the temp file), but because you've moved it, it no longer exists, so it can't get the size.

You may also want to check your php.ini and see what the upload_max_filesize is set to (you might be exceeding that).
Bruce GustPHP Developer

Author

Commented:
Chris!

I did check the upload size settings and I'm gold, so I know that's not an issue.

As far as the "movement" of the uploaded file, is there a sequence of events that I need to be sensitive to?

At what point is the system attempting to get the size of the file? I'm just following my nose with all this, but I'm dropping the ball somewhere...
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
Hey Bruce,

Bit of a baffling one. I've just replicated your code (as much as I can see) and it works exactly as it should - no warnings / exceptions. I can't see where it's trying to get the file size, so if you're not explicitly asking for it, maybe something behind the scenes is requesting it.

Time to go full debug mode - start off by commenting out the $file->move line. If the error stops, uncomment it and then try just dumping the $movie object:

if($movie->save()) {
    dd($movie);
}

Open in new window

We'll need to figure out which line is triggering the getSize() call. Also, is there anything in your Video model or Views that could potentially be the problem.

Out of interest, what version of Laravel are you running.
Bruce GustPHP Developer

Author

Commented:
OK, Chris!

This did the trick:

	if($request->hasFile('thumbnail')) {
			$file = $request->file('thumbnail');
			$thumbnail = $file->getClientOriginalName();
			$file->move('assets/img', $thumbnail);
			$movie->thumbnail=$thumbnail;
		}
			
		$movie->title=$validated['title'];
		$movie->description=$validated['description'];
		$movie->filename=$validated['filename'];
		$success='Video was successfully created!';

Open in new window


This is what I had:

$movie->thumbnail=$thumbnail;
$file->move('assets/img', $thumbnail);

I changed the order so the "move" happened before I attempted to store it.

Why would that make a differrence?
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
Hmmm. Logically, it shouldn't make a difference. Possibly a bug in the version of Laravel you're using (you haven't said which version), or perhaps you have some additional code / trait in your Video Model. As it stands, by reversing those lines, it would appear that this line:

$movie->thumbnail=$thumbnail;

is calling the getSize() method, but that in itself is just setting a property to a string value (unless your Model has additional functionality)

If you're using a version of Laravel later than 5.5 (I tihnk), then you shouldn't really be using the move() method. You should be using the store() method instead. Not sure if that's related.
Bruce GustPHP Developer

Author

Commented:
I'm pretty certain I'm running Laravel 6. I'll check when I get home later this afternoon.
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
If that's the case, I don't know what else to suggest. Like I said, I've tested your code (as provided) in Laravel 6 and it worked perfectly. Obviously I don't have your full codebase, so I don't know if something else is going on,

If switching the lines has fixed the issues, then I'd be happy with that, although I would suggest you consider looking at the store() or storeAs() method on the File, instead of the move() method. That may be part of a more robust solution.
Bruce GustPHP Developer

Author

Commented:
BTW: Laravel 6.1
Bruce GustPHP Developer

Author

Commented:
It's hard to argue with success!