Does anyone know what this error means
FATAL:
Autorisation no longer valid.704
It happens when I try to write to this file, but the permissions are set to 755 and 0644
The temp folder is in the rootfolder of this subdomain.
if ($handle = fopen( 'temp/mylog.log'"a+") )
{
if( !fwrite( $handle, $json ) )
{
throw new Exception("can't write to ...");
}
fclose( $handle );
}
thanks, Richard
Does the user who run that script own that folder/file?
do a list
# ls -l /rootfolder/temp/
to get the user who has privileges to modify the file, I suppose it is root
do from your shell the following to allow your user to access the file (change user with your username)
# chown user /rootfolder/temp/mylog.log
also use the full path in fopen.
UPDATE:
use this simple steps to write file, if you get errors then it may be something related to permissions
$myFile = "/home/woonbel/public_html/tsa.nl/temp/tsa.log";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Some of your text...bla bla\n";
fwrite($fh, $stringData);
fclose($fh);
Related
While testing the following code on my local machine, no error was reported. But after testing it on our server at work, I got the following strange error: php is not writing files on the server.
code I am using :
$myfile = fopen( "results/co".$a[$i].".txt", "w") or die("Unable to open file!");
fwrite($myfile,"some text");
fclose($myfile);
So no file is created in this case.
when I try to replace the file name "results/co".$a[$i].".txt" with its value : "results/co00112test.txt" :
$myfile = fopen( "results/co00112test.txt", "w") or die("Unable to open file!");
fwrite($myfile,"some text");
fclose($myfile);
it works just fine.
I also tried the following:
$name = "results/co".$a[$i].".txt";
$myfile = fopen( $name, "w") or die("Unable to open file!");
fwrite($myfile,"some text");
fclose($myfile);
yet with no hope.
What could be the reason for this error ?
If your code works fine when you're putting some static filename, it's obvious that your variable $a[$i] is wrong.
You can proceed that way to debug it :
$name = "results/co".$a[$i].".txt";
var_dump($name);
The name should show something weird, and will tell you what's happening to your file.
it might be all because of permissions. Your php user don't have permission to folder, where you want to create file or don't have permission to file, which you are trying to edit (if file is already there).
You can read full article about permissions here (it's about ubuntu, but it doesn't really matter which OS): https://help.ubuntu.com/community/FilePermissions
you can try permission 644 or if it's not working you can use 777. 644 is more safe, because only the owner of the file will be able to edit it, not any user of your OS.
you can change permissions to folder and all files/folders in it like this:
chmod -R 644 /path/to/folder/
I think 644 is standard for files and 755 for directories.
you can change owner of the file/folder like this:
chown name_of_user:name_of_group /path/to/folder
Your file name is starting with double zero char so it might be an issue.
this will not work :
$number = 112;
$file_name = "results/co".$number."test.txt";
this should work :
$number = 112;
$number_pad = str_pad($number, 5, '0', STR_PAD_LEFT);
$file_name = "results/co".$number_pad."test.txt";
I cannot update any txt files using php. When I write a simple code like the following:
<?php
// create file pointer
$fp = fopen("C:/Users/jj/bob.txt", 'w') or die('Could not open file, or fike does not exist and failed to create.');
$mytext = '<b>hi. This is my test</b>';
// write text to file
fwrite($fp, $mytext) or die('Could not write to file.');
$content = file("C:/Users/jj/bob.txt");
// close file
fclose($fp);
?>
Both files do exist in the folder. I just cannot see any updates on bob.txt.
Is this a permission error in windows? It works fine on my laptop at home. I also cannot change the php files on my website, using filezilla.
It may very well be a file permissions issue.
Try your code using a direct pointer to the file instead of a path to it, using the following code:
I added a chmod directive. See the comments above chmod ($file, 0644);
Tested succesfully on my hosted WWW website:
<?php
// create file pointer
$file = "bob.txt";
$fp = fopen($file, 'w') or die('Could not open file, or fike does not exist and failed to create.');
// chmod ($file, 0777); // or use 0777 if 0644 does not work
chmod ($file, 0644);
$mytext = '<b>hi. This is my test</b>';
// write text to file
fwrite($fp, $mytext) or die('Could not write to file.');
$content = file("bob.txt");
// close file
fclose($fp);
?>
Perhaps you have to set the permission from bob.txt to 0777 (or something else). In FileZilla it is very easy, because you can just check the permissions you want.
I want to HTTP POST data to a PHP file which will in-turn write the data into a file. The script I used is as follows,
<?php
#error_reporting(E_ERROR | E_PARSE);
$msglen=strlen($_POST["msgarea"]);
$msg=$_POST["msgarea"];
$fp = fopen("dinesh.txt", 'w');
fwrite($fp, $msg);
fclose($fp);
echo "Data Written -> $msg";
?>
I am hosting this script file in sourceforge.
I have already just created the empty file dinesh.txt and placed the file in the same directory as that of the script file. But unfortunately its not written in the file.
What is the reason ?
Thanks in advance
Check that $_POST["msgarea"] is not empty and the file is writeable for the user who tries to write it.
And check the logs for errors of course.
<?php
error_reporting(E_ALL);
var_dump($_POST["msgarea"]);
$msglen=strlen($_POST["msgarea"]);
$msg=$_POST["msgarea"];
$fp = fopen("dinesh.txt", 'w');
$result = fwrite($fp, $msg);
fclose($fp);
if ($result) {
echo "Data Written -> $result";
} else {
echo "Error";
}
I think you are writing in read-only webspace, check file permissions and path
From: http://sourceforge.net/apps/trac/sourceforge/ticket/2772
In generally it is not allowed to write to folders and files that reside in the project's web space. If you need to write to the file system you should use the folder named persistent that is on the same level as htdocs.
I use on my computer:
$ mkdir persistent
$ chmod 0777 persistent
$ scp -r persistent my_account#web.sourceforge.net:/home/project-web/my_project/
And set in PHP:
$fp = fopen("../persistent/dinesh.txt", 'w');
And it works!
Edit:
You can get access for SSH console for 4 hours (https://sourceforge.net/apps/trac/sourceforge/wiki/Shell%20service). And you can go to web directory of your project, make dirs, set privileges, remove files etc. Midnight Commander is available.
you can, check that folder permission, do they have 777 permission
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Bobby Bopper\n";
fwrite($fh, $stringData);
fclose($fh);
I'm want to read a simple string from a text file which is around 3-4 mb but fopen() fails ("can't open file" from die() is called). Here's the code:
clearstatcache();
$fh = fopen("/my/path/to/file.txt", "r") or die("can't open file");
$sql = fread($fh,filesize("/my/path/to/file.txt"));
Have you firstly checked to see if the file exists?
if (!file_exists("/my/path/to/file.txt") {
die('File does not exist');
}
clearstatcache();
$fh = fopen("/my/path/to/file.txt", "r") or die("can't open file");
$sql = fread($fh,filesize("/my/path/to/file.txt"));
you have to add to your code this line
error_reporting(E_ALL);
and ALWAYS keep this line in ALL your codes
and also this line
ini_set('display_errors',1);
and keep this line only on development server.
while on the production it should be changed to
ini_set('display_errors',0);
ini_set('log_errors',1);
By doing this you will not need Stackoverflow assistance in reading the now obvious error messages.
Change that second line to:
$fh = fopen("/my/path/to/file.txt", "r") or die($php_errormsg);
and see what it outputs as the cause.
Try to output system errors in die or try use try…catch. Also turn on php errors while development. Also check if file is readable before open it.
Most common issues are: file does not exists (or just incorrect path provided?), there is not enough permissions to read this file.
In your FTP file permissions tend to need to be 646 (or -rw-r--rw-), not 777 (always ignore those kind of comments). You want to give a key to someone you trust, setting permissions to 777 is like giving a copy of your key to everyone.
You should check that the specified file directory is inside the working directory. You can do this with 'getcwd'
echo getcwd();
If you still get the error, you should check the file permissions.
ls -l /my/path/to/file.txt
If you get this output "-rw-r--r--" you will see the file is writable for admin only.
To make the file writable for everyone use chmod command:
chmod 666 file.txt
You can check again with "ls -l", the z output should be "-rw-rw-rw-"
i want to create a .txt file with the 777 permission for file creation i am using the following code
if(file_exists($myFile) == true)
{
$err = "File Already Exist in The usrlogactity. Try Another Username";
}
else
{
$fh = fopen($myFile, 'w') or die("can't open file");
}
$file = "usrlogactity/$myFile";
$ftp_server="02.79.103.130";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, "use1234", "pass123");
// try to chmod $file to 644
if (ftp_chmod($conn_id, 0777, $file) !== false)
{
//echo "$file chmoded successfully to 777\n";
}
else
{
//echo "could not chmod $file\n";
}
// close the connection
ftp_close($conn_id);
if i execute this code in server it create the file with the 644 permission ,
but gives error. how to i create the .txt file with the 777 permissiom please guide me
The error is
No such file or directory in usrlogactity/$myFile on line 13
To change local file permissions you have to use PHP function chmod(), not using ftp for this
Doing it via FTP you're trying to access this file with ftp user, not www user, and, therefore, no success.
And, you see, how it's important to post your code, not to tell about it? ;-)
it depends on the server if your scripts are allowed to and why do you need 777 for a text file you don't execute a text file you read its 644 is all you need,
but permissions should not be changed by a script different configurations leads to completely different results,
Some servers are idiots and run Apache as root, which mean php writes a file that root owns,
Some use suExec and then your login to your account owns the file
others use Apache user to control your file
so your script could work on one and not on another if you moved the site due to the file becoming unreadable
Allso check safemode on your php install