File_Put_Contents - Failed to Open Stream: Permission Denied

file_put_contents - failed to open stream: Permission denied

Try adjusting the directory permissions.

from a terminal, run chmod 777 database (from the directory that contains the database folder)

apache and nobody will have access to this directory if it is chmodd'ed correctly.

The other thing to do is echo "getcwd()". This will show you the current directory, and if this isn't '/something.../database/' then you'll need to change 'query.txt' to the full path for your server.

Codeigniter file_put_contents: failed to open stream: Permission denied

Do you have check about your directory or permission?

Some problem maybe cause:

  1. Directory Does not exists, you must create it first.
  2. Permissions / Script does not have enough access to write files, you must verify the application could write directory and directory is writable.

Your code also doesn't validate the image content / metadata;

// $data = trim(explode(',', explode(';', $data)[1])[1]);
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
// determine absolute path
$imageDirectory = __DIR__ .'/upload/logo';
// check if string / content is an image
if (! ($imgInfo = getimagesizefromstring($data))) {
// do exit here because data is not a binary image string
throw new Exception('Data is not an image');
}
// check if image directory exist
if (!file_exists($imageDirectory)) {
mkdir($imageDirectory, 755, true);
}
if (!is_dir($imageDirectory) || !is_writable($imageDirectory)) {
throw new Exception('Could not save image. Directory is not writable.');
}

$extension = $imgInfo['mime'];
// optional to filter jpeg image
if ($extension === 'jpeg') {
$extension = 'jpg';
}
// use only time is not recommended due time is not unique, please change with random value
$baseName = time();
$imageName = $baseName . '.' . $extension;
$written = file_put_contents($imageDirectory.'/'.$imageName, $data);

file_put_content...fail to open stream:Permission denied in Laravel 5

is a file permissions issue as lesssugar said , you need to give writte permissions to the storage folder , so go to your html/Tranining-management-system.. folder an then you can do :

chmod -R 0777 storage/

That will change to writte access Recursively .

Please read the configuration section in docs :

http://laravel.com/docs/master#configuration

You have to do the same with the cache folder.

File_put_contents(./composer.lock): Failed to open stream: Permission denied

composer install is trying to create a .composer.lock file in your project directory, so php should have permission to do that.

A quick hack is to use sudo composer install ,but this is not the recommended way.

this should also work

sudo chown -R :www-data /fullpath-to-your-project



Related Topics



Leave a reply



Submit