I have created an upload folder at the same level of app and storing uploaded files there. Now I need to access those file via browser so need to have an http:// based address.
First, am I doing right? What are Laravel 5.1's recommendation? Where should files be stored? If no recommendation then how do I get ULRs?
Store the files within your public folder create uploads folder and then you can simply access from there using asset() function like as
asset("uploads/your_file")
You can use Request::root() to get the root URL of your website and then simply use Request::root()."/uploads/your_file"
Related
I have a web application and I want to save data in a file instead of in the database.
My doubt is, where I should save the file? If I save it under the public directory, I could refer them with the assets to make the correct URL, but in the public directory, any person could see the file writing the complete URL. This shouldn't be because de data is reserved.
I think about the var directory, but I couldn't use the assets to make the correct URL to get or manage the files.
Where I should save the files and how I get/manage them?
If the data-file is local and hosted on the server's file system, the most logical place to store something like that would be the var directory. Although nothing stops you from creating your own "var-like" directory and naming any way you like it. E.g. data. But I would follow the conventions and create var/data, easier for everyone.
That you can't use the asset() function is irrelevant, because a data-file is not a web asset, but an infrastructure concern.
A file like this should not have a URL at all, but you would only access it through it's file system path.
I have form for uploading images in Laravel 5.3. These images are uploaded into directory (project_root/public/uploads/images/). When I turn on the URL example.com/public/uploads/images/filename.png (eg) or example.com/uploads/images/filename.png, I only get 404 NotFoundHttpException.
The images, of course, there are. But I cant dump the contents of a public folder over URL.
Can you help me please? Thanks!
The 'correct' way is to use your Storage facade and store it in the storage/public folder.
This folder is like your public folder, but you can apply all kinds of logic that you don't want to put in your public folder.
Without knowing more about how you are 'dumping' the contents of your public folder (with code or just a get request?) or how you are saving your files, i can't tell you what the problem is. It could be you have made a custom .htaccess rule?
I am creating a small application that is going to read .txt files and put each row of text in the database. I am not sure where to put those .txt files so that it's in accordance with Laravel standards. Should I put those files in the /public/ directory and access them from a controller via public_path() helper function?
The documentation seems to omit that information. I'd appreciate any help.
When using the local driver, note that all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory. Therefore, the following method would store a file in storage/app/file.txt
Laravel Configuration
How can I restrict PHP files from getting executed outside the application folder?
I am using CodeIgniter and I have heard it somewhere that this thing is possible in CodeIgniter.
Temporary, I have added request in htacess which will surpass each request from index file and will result in not found.
Add public folder, move index.php into it, inside index.php change application and system folder settings to ../application and ../system respectively. Point domain to public folder.
my directory structure is like (in ubuntu)
/var/www/mysite/application/(here is code)
i want to store my uploaded photos in
/var/www/mysite/uploads/(a.jpg)
should i use alias in .htacccess file for directory so that it will not expose to other users, where actually directory resides ? but in that case how to display that file in
i refer other Question they said i should use
header('Content-type: image/jpeg');
readfile('/path/to/picture/outside/doc/root/file.jpg');
can you gus plz tell me how to store photos in above mentioned directory structure ?
It depends where is your public folder. If it is the ..../my site/ then just in the config folder set the images folder to be the uploads or use URL::to_asset to point to the specific file. could you tell me where is your public folder of Laravel?
Another - exotic - solution would be to use a "proxy" route that would return the requested image via code.