I have a Laravel 4.2 API that, when creating a resource, accepts file uploads. The file is retrieved with
Input::file('file')
Now I want to write a script (also in Laravel) that will batch create some resources (so I can't use a HTML form that POSTs to API's endpoint). How can I translate a file path into an instance of UploadedFile
so that Input::file('file')
will pick it up in the API?
Laravel's filesystem configuration file is located at config/filesystems.php . Within this file, you may configure all of your filesystem "disks". Each disk represents a particular storage driver and storage location.
Laravel 8.x < You can use the storage_path(); function to get storage folder path.
This is a typical Laravel folder structure, with the default public folder : / /app /bootstrap /config /database /public /index.php /resources /routes /storage. This is specially useful when you try to deploy or publish your application in a standard web server.
To upload files to storage in Laravel, use MAMP or XAMPP as a local web server, define a database name in MySQL, and add the correct configuration in the . env file.
Just construct an instance yourself. The API is:
http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/File/UploadedFile.html
So you should be able to do:
$file = new UploadedFile(
'/absolute/path/to/file',
'original-name.gif',
'image/gif',
1234,
null,
TRUE
);
Notice: You have to specify the 6th constructing parameter as TRUE, so the UploadedFile class knows that you're uploading the image via unit testing environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With