I have the following script to upload files. I've been able to run it successfully except for a newly-provisioned VPS from BlueHost. Here is the code:
// Creating image upload path
$destinationPath = public_path() . sprintf("/uploads/data/users/%d/", Auth::user()->getId());
$realPath = sprintf("uploads/data/users/%d/", Auth::user()->getId());
if (!file_exists($destinationPath)) {
mkdir($destinationPath, 0777, true);
}
$fileName = str_random(16);
$fileName = str_replace('/', 'y', $fileName);
$image_url = $realPath . '/' . $fileName . '.' . $ext;
if ($file->move($destinationPath, $fileName . '.' . $ext)) {
$p->display_pic = $image_url;
}
This is the error I keep getting:
mkdir(): Permission denied
Folder permissions are set to 755 for the parent folder. Why is this happening, and how can I fix it?
When you buy a domain you usually point it to a folder on your server.
Following instructions i found online on how to safely point my laravel project to my domain name without first having to go through the public folder eg:
yahoo.com/home instead of yahoo.com/public_html/home
i moved and renamed the folder my domain was initially pointing to, you will notice that i my code i have:
$destinationPath = public_path() . sprintf("/uploads/data/users/%d/", Auth::user()->getId());
Now what that would usually mean is that it would check for and create the specified folder if non-existent in the root of the folder my domain was pointing to.
Now since my domain was no more pointed to that folder i assume it tried to create that folder in the "home" directory of my server hence "permission denied"
After taking out the preceeding forward slash it works now. :) In case you're wondering about the "public_path()" function i have there i tried echoing it out to the page and it came up empty for that i do not know why maybe someone else can explain.