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:
- Directory Does not exists, you must create it first.
- 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
MySQL Connection Not Working: 2002 No Such File or Directory
Working With Large Numbers in PHP
PHP Preg_Match With Working Regex
How to Choose an Authentication Library For Codeigniter
Continue Processing PHP After Sending Http Response
Highlight the Difference Between Two Strings in PHP
Pass a PHP Array to a JavaScript Function
Why I Have to Call 'Exit' After Redirection Through Header('Location..') in PHP
PHP In_Array()/Array_Search() Odd Behaviour
How to Strip All Spaces Out of a String in PHP
How to Call a Function from a String Stored in a Variable
Mcrypt Is Deprecated, What Is the Alternative
How to Generate in PHP All Combinations of Items in Multiple Arrays
Escaping Quotation Marks in PHP
Sort an Array by Keys Based on Another Array
Simplest PHP Example For Retrieving User_Timeline With Twitter API Version 1.1