What's problem in this code :
$handle = fopen("c:\DIGIPROG\welcome.txt", "rt");
OR
Something problem with another?
I set DIGIPROG folder Full access to everyone but still found error like this :
Warning: fopen(c:\DIGIPROG\welcome.txt): failed to open stream: No such file or directory in C:\xampp\htdocs\digi\test.php on line 1
Then, I tried to open the address directly from run : c:\DIGIPROG\welcome.txt
and it's opened.
My question, is it possible to read using fopen in folder on windows OS ?
Please help with example :)
Thanks
thats surely because the USER running your php executable has no read access to that path.
is a webservice running the php.exe process ? if so, what is the user (use your taskbar) surely it is SYSTEM (by default).
are you running the php script by hand ? then, your user (that used when you login on windows) must have READ permissions in that directory.
in both cases, right click the folder, go to security tab, add read permission to the SYSTEM user (or your user). To make a test only tell ALL USERS have read permission, remember to remove this entry later.
Related
this is not a duplicate question, I read all related questions, and didn't find my answer.
I want to include a file that exists :
/var/www/html/monitor/protected/extensions/curl/curl.php
and my code is :
include('/monitor/protected/extensions/curl/curl.php');
and I'm getting this error :
include(/var/www/html/monitor/protected/extensions/curl/curl.php): failed to open stream: Permission denied
and the file has 777 permission.
My question is :
is it possible that a file exists and have a 777 permission and a proper chown AND still give this error?
Update : I had used all three possible ways :
include('/monitor/protected/extensions/curl/curl.php');
include('monitor/protected/extensions/curl/curl.php');
include('/var/www/html/monitor/protected/extensions/curl/curl.php');
Im using php 5.3
Note: when including another file in the same directory, it includes without any problem
I know this is late, but I just want to confirm Alireza Fallah's answer. This also worked for me. It looks like it has to be the original owner. So unzip/unrar the php files on the same machine you want to use it on. Hope this helps!
You're using the wrong path. If the file exists at
/var/www/html/monitor/protected/extensions/curl/curl.php
Then you should include that exact string.
include('/var/www/html/monitor/protected/extensions/curl/curl.php');
/ means the root of the file system. You get permission denied because you most certainly don't have permission to / and /monitor doesn't exist
Alternatively you can include it relatively. By dropping the first / you would do:
include('monitor/protected/extensions/curl/curl.php');
This will work if the running script is also in /var/www/html.
I think you're getting confused at the difference between the HTTP path and the system path. PHP files are included from the system path and should be referenced by the system path.
I deleted the file, and created again, and my problem solved.
the original file was downloaded from the internet and unzipped from a zipped file.
I think there was a problem with creating the file by original author.
This is very odd! but it worked
I have created a php file that exports data to an excel file using PHPExcel.
On my localhost everything works fine but when I upload it to the live site I get :
Warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 755 is not allowed to access /tmp owned by uid 0 in
I'm not sure if I can fix this with a simple CHMOD or I have to call my server administrator
I am using joomla 1.7.1 if it matters
Thank you
Sounds like 'safe mode' is restricting access to a folder. You need to either disable safe mode or add the folder to the allowed directories. Someone with a similar problem here < http://forums.gplhost.com/phpBB2/image-vp8763.html> .
I suggest you look at your server logs for a more detailed error.Look for instances of open base dir error messages.
The file was created by apache using mkdir() and fopen() etc..
How do i let my php CLI program be allowed to read that file that apache (that is what it says the user is) created so i dont get this error:
Warning: file_get_contents(./sessions/nl2larsjl6n3315mesghmspts7.txt): failed to open stream: No such file or directory in /var/www/html/cli.php on line 58
in the cli this my code for getting the file:
$alert = file_get_contents('./sessions/'.$sessionID.'.txt');
Short answer:
when you create it, you should run chmod(0777) on it.
Long answer:
chmod(0777) means "world readable and writable, and not actually recommended. Checkout http://en.wikipedia.org/wiki/Filesystem_permissions, http://www.linuxforums.org/articles/file-permissions_94.html for a complete explanation on these numbers.
Basically if you need it to be writable by a user, and readable by any user, do a chmod(0644)
EDit: i was quick to wrinte an answer... without reading the question carefully.
You seem to try and open the file from a different directory than the folder where you created it.
Try and see the result on echo getpwd() in the CLI script and then in the script running under www. I bet you will see different locations.
When executing CLI scripts you should either do a chdir() before running the command or use absolute paths at all times for the files you access.
I personally prefer the chdir() method.
I have a PHP web application running on IIS, which allows a user to upload a file from a simple html form. The uploaded file is then moved to a folder on another server. This is working correctly on Apache, but fails on IIS with the error:
function['move_uploaded_file']failed to open stream: Permission denied
in...
I've checked all the permissions on the directories. If I run a simple PHP script through the command line to copy a file from the server into the folder on the other server it works correctly, so I suspect the problem is with IIS.
if (move_uploaded_file($_FILES ["file"] ["tmp_name"], "\\\\000.00.0.00\\tia\\web\\upload\\" .$_FILES["file"]["name"])) {
This has been covered already here. Quoting the reason here:
You have mapped target directory to a share such as \server2\files. These mappings are only available to the current users (eg, the admin account), not to the IUSR account that your php is probably running as (assuming IIS). Solution, don't use mappings, instead use the full 'unc' path name, ie '\server\share\folder\file.ext', also remember that the IUSR account will need access to these shares/folders/files
From what I can see in your comment, you are using a \\ prefixed network share as the target for your move_uploaded_file() operation.
I'll bet a beer that PHP isn't allowed to access that share. Remember, PHP runs with IIS's permissions!
Try saving to a local, globally writable path first. If that works, you know you have to fix the share's permissions.
I have a file in my project folder.How i can i give file write permission using php.I used this code
chmod($file,0777);
But it giving an error
Warning: chmod() [function.chmod]: Operation not permitted
The file is created by another user.Is their any way to do this .Thanks in advance
This happens because PHP does not have rights to do the change. The user under which PHP runs is usually the web server's user and different from the user you use to add files.
You generally only do chmod on files created with PHP. To be able to do this on other files you need to change the owner (chown).
The current user is the user under
which PHP runs. It is probably not the
same user you use for normal shell or
FTP access. The mode can be changed
only by user who owns the file on most
systems.
From http://php.net/manual/en/function.chmod.php
Well - you just can't if it says you are not permitted to.
Point is - the file belongs to some user and group, most likely root:root - and you are just a user on the server. If root's the owner of that file, you can't change the permissions at all.
Notes:
$file must be a filename. If you put the handle there, the file (most likely) doesn't exists, but still.
Check if the filename is not beginning with / or something. Try different variations.
you can install php via SUEXEC or SUPHP instead of mod_php which allows to change the user as which php is executed, still this dosnt solve anything if the owner is set wrong