-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.2] After move of uploaded file, missing temp file error. #12350
Comments
Can you give me some code I can use to recreate this in a fresh Laravel application? |
This could be related to #12299. I'm also still having problems with this since the |
@vinkla Is it broken in 5.2.19? |
@GrahamCampbell Yeah, or it has at least changed in behaviour. My tests fails in versions |
@GrahamCampbell @vinkla You are correct. The problem surfaced in 5.2.15. Rolling back to .14 works. We can produce this consistently across 20+ sites. It almost appears that once you upload a file and take any action (in our case sanitize then move), it kind of bombs anything else in the request scope. For example after moving the file an then using another form variable (non file related one) it throws the error as stated. A couple more people have reported it here: |
|
Controller
|
Request
|
Form
|
Hmm, I still can't recreate this with this code sample :| |
What version of Laravel are you on? |
I don't know which version @trwilliams are using but @magnetion and I have issues with |
@vinkla does the code snippet above break for you on 5.2.19? |
@taylorotwell It started happening in 5.2.15 and was occurring yesterday in 5.2.19. |
OK, can someone give me maybe a different code snippet you have I might can use to recreate @vinkla or @magnetion ? |
@taylorotwell After the following runs, anything that occurs after this will error with the temp file does not exist error. So after running the code below, if you try and reference $request->anyformfield it errors. if (Request::hasFile('image')) :
$image = Request::file('image');
$uniqueName = Universal::getUniqueFilename('storage/product', $image->getClientOriginalName());
Request::file('image')->move('storage/product', $uniqueName);
endif; |
But, it doesn't for me. That's why I'm confused. It keeps working fine even after moving the file. |
It happens in any version above 5.2.14. Also it only happens when getting the file form a request object. But it works if you get the request like this. Actually everything does go through and upload fine, but it throws the error. If you go to a different page and come back you will see the it did upload correctly, we just can't have the error. |
This is taken from my test method. factory(User::class)->create();
Storage::put('test.png', base64_decode('imagedata'));
$path = public_path('images/uploads/test.png');
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $path);
$this->call('POST', 'users/1/images', [], [], ['image' => new UploadedFile($path, 'test.png', $mime, null, null, true)]);
$this->seeJson(['type' => 'image']);
$this->assertResponseStatus(201);
exec('rm '.public_path('images/uploads/*.png')); This is taken from my controller method. $image = $request->file('image');
$name = strtolower(Uuid::uuid4().'.'.$image->getClientOriginalExtension());
// This is where is fails for me.
$image->move(public_path('images/uploads'), $name); Let me know if there is anything else I can provide. |
@vinkla are you using a FormRequest or just the normal Illuminate\Http\Request? |
Also @vinkla have you looked into the core at all to see where there might be a fix needed? |
In first message. here are the lines that need looked at. laravel/framework/src/Illuminate/Http/UploadedFile.php If I remove instanceof static it works fine. The function is called from laravel/framework/src/Illuminate/Http/Request.php |
I'm using |
@trwilliams so what does your full patched method look like with the instanceof static removed? Really wish I could recreate this but can't even with a Form Request. @trwilliams is yours triggered from a unit test or web UI? |
Also what version of PHP? |
PHP 5.6.8
|
I'm using PHP |
Also happening on 5.5.9 |
@trwilliams that would break other things. I will have to recreate this first I guess before proceeding. I've still not been able to. |
You don't have cached compiled.php files with old versions of things do you? |
@taylorotwell didn't work for me 😞 still works on |
OK. ill tag this in a bit. |
@vinkla really? so your unit test is still broken? you dont have a compiled file in the way do you? |
@taylorotwell no, I removed it before I tried to run the unit tests again. |
OK Ill try to recreate your unit test problem. |
Cool, let me know if there is anything else I can provide. |
@vinkla what is the exact error message you receive from your test? |
@vinkla I think I know your issue. See if passing an instance of |
@taylorotwell okay, great. I will try it first thing tomorrow morning. |
@taylorotwell with |
@vinkla You should create |
@CasperLaiTW Yeah, that is what made it work. Though, upgrading to |
I was also fall on this problem in |
@taylorotwell After I move the uploaded file to a directory I make a call to a package class, but this package calls 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! |
I got the same error. I discovered that my php.ini file was limiting my file upload to 2mb. I changed this and solved the error. |
I recently got same error on laravel 5.4 and php 5.6.4 (1/1) FileNotFoundException
|
think resetting $_FILES before redirecting or Request::createFromGlobals() would work : $_FILES = array(); //reset fileBag |
@Mokolos Thank you, indeed that worked. |
@Mokolos you good man, worked
|
Best option is just copy file so it will be on place for |
face same issue, after i check this was caused by http request instance. |
I am using Laravel 7.8.1. Any suggestion?? |
@hendisantika I am facing the same issue. After moving a file to S3 not able to read from the |
where can i put this line ? |
put this line inside loop or top of controller ? |
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
The text was updated successfully, but these errors were encountered: