According to fopen documentation, in some modes it will create the file if it does not exist, but in my situation, I've checked all 'w', 'w+', 'x' and 'x+' modes but it's just throwing warnings at me and it cannot create the file.
It's my code:
$this->handle = fopen($this->log_name, 'w');
and what I get:
Warning: fopen(D:\xampp\htdocs\farid\logs\error.php) [function.fopen]: failed to open stream: No such file or directory in D:\xampp\htdocs\farid\libraries\error\log.php on line 34
Warning: fwrite() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\farid\libraries\error\log.php on line 66
Warning: fclose() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\farid\libraries\error\log.php on line 27
And I'm working in windows environment.
Check if the path to the logfile exists, it creates a file, not a directory.
Also check if the user, which runs xampp, has access to the folder you specified.
Related
I am trying to install a new theme. After copying it to the themes folder and entering the themes admin panel to activate the theme I get 3 warning error:
Warning: fopen(C:\wamp\www\wordpress/wp-content/themes/idealdevelopments/style.css) [function.fopen]: failed to open stream: Permission denied in C:\wamp\www\wordpress\wp-includes\functions.php on line 4782
Warning: fread() expects parameter 1 to be resource, boolean given in C:\wamp\www\wordpress\wp-includes\functions.php on line 4785
Warning: fclose() expects parameter 1 to be resource, boolean given in C:\wamp\www\wordpress\wp-includes\functions.php on line 4788
Change your folder permissions.
I have the following test page
mkdir('test');
$f = fopen('test.txt', 'w+');
fwrite($f, 'gibberish');
fclose($f);
unlink('test2.txt');
Nothing of that happens and I get the following error messages on erro.log
PHP Warning: mkdir(): Permission denied in /var/www/html/test.php on line 5
PHP Warning: fopen(test.txt): failed to open stream: Permission denied in /var/www/html/test.php on line 7
PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/html/test.php on line 8
PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/html/test.php on line 9
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/html/test.php on line 10
PHP Warning: unlink(teste2.txt): Permission denied in /var/www/html/test.php on line 12
I can clearly see that I'm having permission issues, but I have no ideia what sort of permission it is and how do I even set that kind of permission.
Using git or terminal I can create/delete/chmod all files and directories without a problem. It's just PHP that can't.
ssh using your terminal and, first, change the files owner to apache group
chown -R www-data:www-data /var/www/html/
Next allow all members of this group to read and write files
chmod -R g+rw /var/www/html/
This should fix your issue. I strongly suggest you read more about permissions in ubuntu though
When I hit the refresh button in the admin > Extensions > Modifications page the page crashes and produces a page of failure errors in OpenCart 2.1.0.2
Following error got. Please help me. how can i fixed this issue.
Warning:
fopen(/home/onlybrands1/public_html/system/modification/system/engine/action.php)
failed to open stream: No such file or directory in
/home/onlybrands1/public_html/admin/controller/extension/modification.php
on line 408
Warning: fwrite() expects parameter 1 to be resource, boolean given in
/home/onlybrands1/public_html/admin/controller/extension/modification.php
on line 410
Warning: fclose() expects parameter 1 to be resource, boolean given
in
/home/onlybrands1/public_html/admin/controller/extension/modification.php
on line 412
Warning:
fopen(/home/onlybrands1/public_html/system/modification/system/engine/loader.php):
failed to open stream: No such file or directory in
/home/onlybrands1/public_html/admin/controller/extension/modification.php
on line 408
Warning: fwrite() expects parameter 1 to be resource, boolean given
in
/home/onlybrands1/public_html/admin/controller/extension/modification.php
on line 410
Warning: fclose() expects parameter 1 to be resource,
boolean given in
/home/onlybrands1/public_html/admin/controller/extension/modification.php
on line 412
Warning:
fopen(/home/onlybrands1/public_html/system/modification/system/library/config.php):
failed to open stream: No such file or directory in
/home/onlybrands1/public_html/admin/controller/extension/modification.php
on line 408
Warning: fwrite() expects parameter 1 to be resource,
boolean given in
/home/onlybrands1/public_html/admin/controller/extension/modification.php
on line 410
Warning: fclose() expects parameter 1 to be resource, boolean given
in
/home/onlybrands1/public_html/admin/controller/extension/modification.php
on line 412
Warning:
fopen(/home/onlybrands1/public_html/system/modification/system/library/language.php):
failed to open stream: No such file or directory in
/home/onlybrands1/public_html/admin/controller/extension/modification.php
on line 408
Warning: fwrite() expects parameter 1 to be resource, boolean given
in
/home/onlybrands1/public_html/admin/controller/extension/modification.phpon
line 410
Warning: fclose() expects parameter 1 to be resource, boolean given
in
/home/onlybrands1/public_html/admin/controller/extension/modification.php
on line 412
Warning: Cannot modify header information - headers already sent by
(output started at /home/onlybrands1/public_html/admin/index.php:80)
in /home/onlybrands1/public_html/system/library/response.php on line
12
Just change the permission of the ~/system/modification/ folder to writeable (777).
Reference Link: http://forum.opencart.com/viewtopic.php?t=144373
I have realized. this issue happen with wrong path in config.php file. has been modification folder location change(inside storage folder) than older version in OpenCart 2.1.0.2 by OpenCart.
and, Some user install OpenCart with quick setup feature from Hosting provider services. So, there, The proper path is not set in the config.php file with Hosting quick install feature in OpenCart 2.1.x. Version.
Here, You will need to set properly path for DIR_CACHE DIR_DOWNLOAD DIR_LOGS DIR_MODIFICATION DIR_UPLOAD in config.php(front & admin both config.php) file.
Wrong path for OpenCart 2.1.0.2. (this following path is for 2.0.x version)
define('DIR_CACHE', 'YOURSITE/system/cache/');
define('DIR_DOWNLOAD', 'YOURSITE/system/download/');
define('DIR_LOGS', 'YOURSITE/system/logs/');
define('DIR_MODIFICATION', 'YOURSITE/system/modification/');
define('DIR_UPLOAD', 'YOURSITE/system/upload/');
Correct Path for OpenCart 2.1.0.2. Here, You will need to add /storage/ in following path. (front & admin both config.php file)
define('DIR_CACHE', 'YOURSITE/system/storage/cache/');
define('DIR_DOWNLOAD', 'YOURSITE/system/storage/download/');
define('DIR_LOGS', 'YOURSITE/system/storage/logs/');
define('DIR_MODIFICATION', 'YOURSITE/system/storage/modification/');
define('DIR_UPLOAD', 'YOURSITE/system/storage/upload/');
Hope this will helpful for you.
I was facing the similar issues from Loopback IP address. But on the live site, warnings were suppressed, since storage directory was manually moved to YOURSITE/system/storage and incorrectly configured in config.php and I couldn't get the Front-End display since it was showing
Go to admin, find Extensions >> Modifications and click 'Refresh'
button. To apply the changes characterized by the uploaded
modification file
In OpenCart 3.0.2.x version, there is a notification from admin side:
It is very important that you move the storage directory outside of the
web directory (e.g. public_html, www or htdocs)
The above quote was not showing in order to rectify the root cause of the issue and after correcting the config.php. It began to show in the pop-up screen and finally noticed, this was the issue. Follow the below procedure to get rid:
Changing the following code from both the front-end & admin-end in config.php file
From
define('DIR_STORAGE', 'YOURSITE/storage/');
To
define('DIR_STORAGE', 'YOURSITE/system/storage/');
and modifying
$ sudo chmod -R 777 /var/www/html/YOURFOLDER/*
solved the issue from both front-end as well as in back-end
Problem 1:
I got this code
<?php
$count_my_page = ("adminpanel/hitcounter.txt");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
?>
Its in a file called /beta/ but i need it to find the folder /adminpanel/ i tried using /../ and // it did not work. I created the error reporting file and this is the output:
Warning: file(//adminpanel/hitcounter.txt): failed to open stream: No such file or directory in /home/u463251352/public_html/beta/index.php on line 3
Warning: fopen(//adminpanel/hitcounter.txt): failed to open stream: No such file or directory in /home/u463251352/public_html/beta/index.php on line 5
Warning: fputs() expects parameter 1 to be resource, boolean given in /home/u463251352/public_html/beta/index.php on line 6
Warning: fclose() expects parameter 1 to be resource, boolean given in /home/u463251352/public_html/beta/index.php on line 7
How do i fix this?
You should use an absolute path based on magic constants.
For 5.3.0 or higher, you can use:
__DIR__
For PHP lower than 5.3.0, use:
dirname(__FILE__)
Example:
$file = __DIR__ . '/dir/file.txt';
Will take:
Root
dir
file.txt
or you can use
$_SERVER['DOCUMENT_ROOT'].'/adminpanel/hitcounter.txt';
I am trying to install php code sniffer. I have manage to get to a point where after running
php /Users/ryanfernandes/pear/bin/phpcs --version it display the info. but when I try to run code sniffer by
php /Users/username/pear/bin/phpcs /Users/username/development/htdocs/test.php
PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 155
Warning: fwrite() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 155
PHP Warning: stream_get_meta_data() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 206
Warning: stream_get_meta_data() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 206
PHP Warning: file_get_contents(): Filename cannot be empty in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 208
Warning: file_get_contents(): Filename cannot be empty in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 208
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 209
Warning: fclose() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 209
Any help would be really appreciated.
Thanks
From the error messages, it looks like you are using PHP_CodeSniffer version 1.5.4. PHP_CodeSniffer uses the tmpfile() function to create a temporary file. The directory that it is created in can be found by running:
php -r 'echo sys_get_temp_dir().PHP_EOL;'
Make sure you are allowed to write to that directory because the tmpfile() method is obviously returning FALSE, which most commonly happens if the directory is not writable.