Reputation: 24061
I send my image to php like so:
var formData = new FormData();
formData.append('file', file);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/upload', true);
xhr.onload = function(e) { console.log(e) };
xhr.upload.onprogress = function(e) {
//loading bar
};
xhr.send(formData);
Then I get my file in php like so:
$data = Input::All();
var_dump($data['file']);
This outputs:
"object(Symfony\Component\HttpFoundation\File\UploadedFile)#9 (7) { ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> bool(false) ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(9) "space.jpg" ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(10) "image/jpeg" ["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(50974) ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(0) ["pathName":"SplFileInfo":private]=> string(14) "/tmp/phpzMyVkq" ["fileName":"SplFileInfo":private]=> string(9) "phpzMyVkq"}
My question is, how can I get the file from the object for image processing?
Upvotes: 2
Views: 227
Reputation: 3038
Use the move method to save the file from the tmp position where it is saved to where you need it:
$data['file']->move($destination_dir,$file_name);
Upvotes: 1
Reputation: 21531
Use the file method on input...
$file = Input::file('file');
Take a read of the documentation to see what methods are available... http://laravel.com/docs/requests#files
Upvotes: 2