Asked  7 Months ago    Answers:  5   Viewed   32 times

The server which I'm hosting my website does not support links so I cannot run the php artisan storage:link to link my storage directory into the public directory. I tried to remake the disk configuration in the filesystems.php to directly reference the public folder but it didn't seems to work either. Is there a way to upload a file using Laravel libraries directly into the public folder or will I have to use a php method? Thanks in advance.



You can create a new storage disc in config/filesystems.php:

'public_uploads' => [
    'driver' => 'local',
    'root'   => public_path() . '/uploads',

And store files like this:

if(!Storage::disk('public_uploads')->put($path, $file_content)) {
    return false;
Wednesday, March 31, 2021
answered 7 Months ago

Try adding processData: false, contentType: false in your code

Replace your script with this:

function submitDocument(){
var formData = new FormData(); // Currently empty
var _token = $("#_token").val().trim();
formData.append('title', $("#title").val());
  url: "documents",
  method: "post",
  cache : false,
  processData: false,
  contentType: false
}).done(function(data) {

return false;// Not to submit page

By default, data passed in to the data option as an object will be processed and transformed into a query string, fitting to the default content-type "application/x-www-form-urlencoded". If you want to send a DOMDocument, or other non-processed data, set this option to false.

Wednesday, March 31, 2021
answered 7 Months ago

Your server can't locate storage as path because it uses public_path run

php artisan storage:link

It should work. Also, try to use

{{ asset('storage/'.$ad->avatar) }}
Wednesday, March 31, 2021
answered 7 Months ago

Reading the comments I think you want to do the following:

  • Editing anothers profile (or anything else)
  • your rights have to be higher than the ones of the other account
  • everything should be logged by the user that changed the entries, not by the owner

The following solutions are build in ones, maybe there are some packages for laravel to solve this kind of problem.

Auth::loginById($otherUserId) could be one solution:

  • you have to check if the user is allowed to log in in this profile
  • you have to remember your own user id (in a session) to add it for the log
  • you can access only the pages the user can see (not the admin pages)

Another approach would be to use Policies

e.g. you are user 1 and want to edit the profile of user 3. in the update function user/3/profile. You call a policy function where you check if your user_role_id is smaller than the other ones. Then the record will be saved and the logger will log it away with your user id.

Both ways have pros and cons. Login with the id will give you exact the view of the other user. But you have to modify your logger (instead of Auth::id() use something with a session). Then you can implement a little button with (jump back to own profile) to login back in your own account. Using polices will be easier for the logger, but at every part you have to implement the check with the policy.

Not knowing the size and complexity of your project I would suggest the first solution. I implemented it by myself in one project but without the logger function.

Saturday, August 14, 2021
answered 2 Months ago

If your goal is to upload a file to a directory you shouldn't have to use Carrierwave or Paperclip. Those gems have a lot of support for image processing and extra options.

I suggest you look at the Ruby file class and the open method to be more specific.

Something like the following should do the trick:

# "public/csv" is the directory you want to save the files in
# upload["datafile"] is the data populated by the file input tag in your html form 
path = File.join("public/csv", upload["datafile"].original_filename), "wb") { |f| f.write(upload["datafile"].read) }

Keep in mind, your public directory is accessible to the world. If you need to save these in a more private location, make sure the directory is only readable and writable by your app.

Also, if you are working with CSV files, be sure to read through the Ruby CSV class: It makes working with CSV files a breeze.

Sunday, August 15, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :