I'm using Laravel , The following code works on my local machine (Mac)
$Avatarpath = base_path()."/uploads/image/avatar.png"
$filePath = base_path()."/uploads/image/myimage.png" //which gives "/var/www/myproject/uploads/image/myimage.png"
return Response::download(file_exists($filepath) ? $filepath :$Avatarpath);
but when I deploy the same code on linux (Centos) server , it throws the following Exception
throw new FileException('File must be readable.');
Additional info: "uploads" folder has drwxr-xr-x (775) permissions
Thank you your interest to fix this issue.
Important is that the permissions for the file itself are correct too!
Usually in this cases you should run chmod with the recursive flag (-R):
chmod -R 775 uploads/
This Exception is thrown if function http://php.net/manual/en/splfileinfo.isreadable.php is returning false.
Your file permissions must be denying the file read.
Related
When I upload files (move actually) to the public folder in laravel 8, they are stored as .tmp files and when I attempt to store files in storage folder, it says failed to open stream: permission denied. Is there some kind of write permission I should enable? or am I missing something in the code?
if($request->file('file')) {
$uniqueFileName = uniqid() . $request->file('file')->getClientOriginalName();
$post = new Post();
$post->name = request('name');
$post->email = request('email');
$post->doc = $uniqueFileName;
$request->file('file')->move(public_path('uploads/files',$uniqueFileName));
//I also tried to store files here, but says "failed to open stream: permission denied"
//$request->file('file')->store('uploads');
$post->save();
return redirect()->back();
}
You need to change the permissions using this command: chmod -R 777 storage
Try on terminal sudo chmod -R 777 public it will change the directory permission
had the same issue with a similar approach.
fixed it by manually changing the php.ini
changed the entry upload_max_filesize = 2000M
! dont try to change it within your scripts with ini_set(), it doesnt work for this entry. why? -> check changeable https://www.php.net/manual/en/ini.list.php !
mby php checks the file_size AFTER its uploaded and denies permission if it exceeds the value which is set? dont know. but works for me...
some folks may also run into:
PHP Warning: POST Content-Length of XXX bytes exceeds the limit of XXX bytes in Unknown on line 0
fixed it by manually changing the php.ini
changed the entry post_max_size = 2000M
I use on my application some fonctions about files. creation of files, copy/create from a directory to another, update. On my localhost, all is okay, that's work.
The main purpose is to have a manager for translation on the website.
rights of parent directories : 755
I have error :
1) if files doesn't exist the error is
copy(/blabla/path.php): failed to open stream: Permission denied
2) if I create files before (touch + chown on usr:usr) with basic rights (644) or with updated rights (775) :
file_put_contents(/blabla/path.php) : failed to open stream: Permission denied
On my localhost :
right of directories : 755
right of files : 644
I also tried to clean php cache (php artisan cache:clear)
edit :
I use 2 functions :
copy (who copy default translate file in the directory of second langage) and file_put_contents (who edit file)
public function replaceSlugs(Array $slugs,$filename, $lang)
{
$file=$this->path2File($filename,$lang);
if(!file_exists($file)){$this->duplicateFile($lang,$filename);}
$translate="<?php return ".var_export($slugs,true).";";
return file_put_contents ( $file , $translate, LOCK_EX );
}
private function duplicateFile($lang,$filename)
{
copy($this->path2File($filename),$this->path2File($filename,$lang));
}
private function path2File($filename,$lang="en")
{
return resource_path('lang/'.$lang.'/'.$filename.'.php');
}
Solution is Risky but it will do the trick
Give your folders full permission & clear Cache
Something like this.
sudo chmod -R 777 public/lang/en
if you don't give 777 permission you will also stuck while unit Test.
The error I am getting is
Warning: Phalcon\Mvc\View\Engine\Volt\Compiler::compileFile(../app/views/index/index.phtml.php): failed to open stream: Permission denied in /Users/mattstephens/Sites/magpie/public/index.php on line 26 Phalcon Exception: Volt directory can't be written
I have declared the volt engine usage in my bootstrap like so
$view->registerEngines(array(
'.phtml' => 'Phalcon\Mvc\View\Engine\Volt'
));
The mention of line 26 in my code points to the application handle function shown below
echo $application->handle()->getContent();
Is this a permissions related thing or due to a missing directory?
Unless you specify a different folder for Volt to compile its templates, the folder where the view file is located will be used to create the relevant compiled file.
You can change this behavior by setting the proper option when you register your service as such:
use \Phalcon\Mvc\View as PhView;
use \Phalcon\Mvc\View\Engine\Volt as PhVolt;
...
public function initView($options = array())
{
$config = $this->di['config'];
$di = $this->di;
$this->di['volt'] = function ($view, $di) use ($config) {
$volt = new PhVolt($view, $di);
$volt->setOptions(
array(
'compiledPath' => $config->app_volt->path,
'compiledExtension' => $config->app_volt->extension,
'compiledSeparator' => $config->app_volt->separator,
'stat' => (bool) $config->app_volt->stat,
)
);
return $volt;
};
/**
* Setup the view service
*/
$this->di['view'] = function () use ($config, $di) {
$view = new PhView();
$view->setViewsDir($config->app_path->views);
$view->registerEngines(array('.volt' => 'volt'));
return $view;
};
}
The $config will store all the information you need. By using the compiledPath you instruct Volt to compile the templates there and then serve them to the front end. That folder needs to be writeable for the user that runs your web server www-data or other and can be outside your public folder.
The file structure I usually use is:
app
\controllers
\models
\views
public
\js
\css
\img
var
\volt
\logs
\config
\cache
Change volt file permission (Inside app/cache) to 777 .Its working fine
Contrary to several of the other answers here, don't just willy-nilly set permissions to 0777 and pretend everything's okay, that's completely ridiculous. Your server needs to write to the volt folder inside your cache directory.
You might need to create the folder first.
sudo mkdir cache, and sudo mkdir cache/volt. Then chown that folder with whatever is the username that your server runs.
NOTE: Depending on your configuration, the cache folder might be located at the project root and not inside app.
For example, if your server launches under the permissions of user named 'www-data' (which is most common), after creating the proper folder structure, the following command will fix your issue:
sudo chown www-data:www-data -R cache
I have just made "app/cache" folder with 777 permitions) It works))
change the "app/cache" folder permission to 777.
in my mac i did like this.
navigate inside the app folder of our phalcon framework
[chmod ugo=rwx cache]
make sure the cache folder permission is 777 by typing [ls -l].
Changing the app/cache and app/cache/volt with these commands worked for my project structure.
chmod -R a+w app/cache
chmod -R a+w app/cache/volt
Just go to /project_name/store/app/config/config.php and change cacheDir from 'cacheDir' => __DIR__ . '/../../app/cache/' to 'cacheDir' => __DIR__ . '/../../cache/'.
Also, change its write permission to 777.
You should change ownership of your project directory with chown command,
chown -R your_system_user:webserver_user yourproject/
Check if the baseUri in the config.php is same as the installation directory
if the issue persist, tail nginx logs tail -f /var/log/nginx/*.log.
Also try use sudo setenforce 0. This worked for me.
I am using Zend Framework to upload files and am getting a destination not writeable error EVEN THOUGH the directory is chmodded 777
$adapter = new Zend_File_Transfer_Adapter_Http();
$path=APPLICATION_PATH."/tmp";
// die($path);
$adapter->setDestination($path);
Following is the directory tree
/var 755
/www 755
/attendance 777
/tmp <-- writeable 777
This is a really wierd error. In the past, after chmodding, the error generally went away. This is a local server(Fedora 17)
PHP Version 5.4.17
Apache/2.2.23 (Fedora)
php safe mode is off, atleast there is no entry in config files, nor could I see it anywhere in the phpinfo();
I've been trying for 8 hours, but no cigar, not even a Dunhill
After searching the internet find an answer I've decided to ask for help directly.
I am running mac os x 10.7, PHP, Apache and MySQL. I am trying to let a user select files from a form have them zipped and sent to the individual. At first PHP couldn't even create a file. I found the following:
sudo chmod -R +a "_www allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" ~/Sites
Which allowed me to create a file. But when I try to create a zip I get some unknown extension being appended at the end and 2 files are being created. So not knowing what was wrong I thought I would just find the file by opening the directory and forcibly renaming it back to *.zip. I have checked the file after renaming manually and it seems to be fine.
I get the following error:
Warning: rename(tmp/RosenData082112-1102.zip.ohoKRw,RosenData082112-1102.zip) [function.rename]: Permission denied in /Users/mmcri/Sites/rosenlab/download.php on line 42
ls -le reveals this to the files:
-rw-------+ 1 _www staff 43775 Aug 21 11:02 RosenData082112-1102.zip.1qJUE4
0: user:_www inherited allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity
-rw-------+ 1 _www staff 43775 Aug 21 11:02 RosenData082112-1102.zip.ohoKRw
0: user:_www inherited allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity
Here is the PHP code section making the zip file:
if(extension_loaded('zip'))
{
$zip = new ZipArchive();
$zipname = "RosenData".date("mdy-Hi").".zip";
if($zip->open($direct.$zipname, ZIPARCHIVE::CREATE) === TRUE)
{
foreach($filelist as $file)
$zip->addFile($path.$file,$file) or die ("Error adding file: $file");
$zip->close();
}
// Random stuff below
}
Any help is greatly appreciated.
Thanks.
Do you have permissions to write on that folder in Mac?
Try with fopen instead of ZipArchive.