EvilZone
Programming and Scripting => Web Oriented Coding => : lucid November 20, 2012, 05:54:36 AM
-
Sorry for such an uninteresting question. But, here goes. For some reason fopen doesn't seem to work for me. Here's the relevant part:
$fileName = "file.txt";
$fileHandle = fopen($fileName, 'w') or die("can't open file");
fclose($fileHandle);
When I run it, it simply returns "can't open file". I've made sure to chmod the file to give it write permissions but it still simply won't work.
-
Not familiar with PHP, sorry. :-[
-
Works fine here. Are you sure that:
- file.txt belongs to the same user than your PHP script is running as, and has +w ?
- file.txt has o+w ?
Have you tried chmod'ing 777 that file?
What have you got in open_basedir php.ini's line?
It is everything I can think about right now...
-
check you php.ini file
standard is that you can only write to temp directory
-
I've tried chmod 777-ing the php script as well as chmod u+w. I can't do any of that to the file because it won't be created. I suppose I'll look around more in my php.ini file.
-
I've tried chmod 777-ing the php script as well as chmod u+w. I can't do any of that to the file because it won't be created. I suppose I'll look around more in my php.ini file.
chmod the whole folder
-
Hmmm, that didn't work either. Everything other script seems to operate fine could that still mean it's something wrong with my php.ini?
-
lucid, have you tried chmod($filename, 0777) ;
-
Well so far I have chmod-ed the php file as well as the whole directory. I have done chmod 777, chmod u+w, chmod o+w, chmod u+x, just to be thorough. Nothing has worked. I'm not exactly sure what to look for in my php.ini file considering that everything else works perfectly fine.
I can't chmod the actual file because it doesn't exist. I could create it myself but I thought that was the point of creating it in php :P
-
Well so far I have chmod-ed the php file as well as the whole directory. I have done chmod 777, chmod u+w, chmod o+w, chmod u+x, just to be thorough. Nothing has worked. I'm not exactly sure what to look for in my php.ini file considering that everything else works perfectly fine.
I can't chmod the actual file because it doesn't exist. I could create it myself but I thought that was the point of creating it in php :P
is the folder you want to create the file to on another drive?
try writing to the same folder you have the script in or the /tmp folder
check the php error log, or write the error output (remove the die())
(http://evilzone.org/data:image/gif,GIF89a%12%00%12%00%B3%00%00%FF%FF%FF%F7%F7%EF%CC%CC%CC%BD%BE%BD%99%99%99ZYZRUR%00%00%00%FE%01%02%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00!%F9%04%04%14%00%FF%00%2C%00%00%00%00%12%00%12%00%00%04X0%C8I%2B%1D8%EB%3D%E4%00%60(%8A%85%17%0AG*%8C%40%19%7C%00J%08%C4%B1%92%26z%C76%FE%02%07%C2%89v%F0%7Dz%C3b%C8u%14%82V5%23o%A7%13%19L%BCY-%25%7D%A6l%DF%D0%F5%C7%02%85%5B%D82%90%CBT%87%D8i7%88Y%A8%DB%EFx%8B%DE%12%01%00%3B)(http://evilzone.org/data:image/gif,GIF89a%12%00%12%00%B3%00%00%FF%FF%FF%F7%F7%EF%CC%CC%CC%BD%BE%BD%99%99%99ZYZRUR%00%00%00%FE%01%02%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00!%F9%04%04%14%00%FF%00%2C%00%00%00%00%12%00%12%00%00%04X0%C8I%2B%1D8%EB%3D%E4%00%60(%8A%85%17%0AG*%8C%40%19%7C%00J%08%C4%B1%92%26z%C76%FE%02%07%C2%89v%F0%7Dz%C3b%C8u%14%82V5%23o%A7%13%19L%BCY-%25%7D%A6l%DF%D0%F5%C7%02%85%5B%D82%90%CBT%87%D8i7%88Y%A8%DB%EFx%8B%DE%12%01%00%3B)
-
is the folder you want to create the file to on another drive?
try writing to the same folder you have the script in or the /tmp folder
check the php error log, or write the error output (remove the die())
(http://evilzone.org/data:image/gif,GIF89a%12%00%12%00%B3%00%00%FF%FF%FF%F7%F7%EF%CC%CC%CC%BD%BE%BD%99%99%99ZYZRUR%00%00%00%FE%01%02%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00!%F9%04%04%14%00%FF%00%2C%00%00%00%00%12%00%12%00%00%04X0%C8I%2B%1D8%EB%3D%E4%00%60(%8A%85%17%0AG*%8C%40%19%7C%00J%08%C4%B1%92%26z%C76%FE%02%07%C2%89v%F0%7Dz%C3b%C8u%14%82V5%23o%A7%13%19L%BCY-%25%7D%A6l%DF%D0%F5%C7%02%85%5B%D82%90%CBT%87%D8i7%88Y%A8%DB%EFx%8B%DE%12%01%00%3B)(http://evilzone.org/data:image/gif,GIF89a%12%00%12%00%B3%00%00%FF%FF%FF%F7%F7%EF%CC%CC%CC%BD%BE%BD%99%99%99ZYZRUR%00%00%00%FE%01%02%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00!%F9%04%04%14%00%FF%00%2C%00%00%00%00%12%00%12%00%00%04X0%C8I%2B%1D8%EB%3D%E4%00%60(%8A%85%17%0AG*%8C%40%19%7C%00J%08%C4%B1%92%26z%C76%FE%02%07%C2%89v%F0%7Dz%C3b%C8u%14%82V5%23o%A7%13%19L%BCY-%25%7D%A6l%DF%D0%F5%C7%02%85%5B%D82%90%CBT%87%D8i7%88Y%A8%DB%EFx%8B%DE%12%01%00%3B)
Yeah I'm writing the file to the same directory as the php script. Which is in my home folder. And I have that folder set as the open_basedir and it's worked fine up until now. As for writing the error it brings me back to an old problem. I can't get any errors. I've made thoroughly sure that I enabled all errors in the php.ini too.
error_reporting
error_reporting E_ERROR E_WARNING E_PARSE
Default Value: E_ALL E_NOTICE E_STRICT E_DEPRECATED
Development Value: E_ALL
Production Value: E_ALL E_DEPRECATED E_STRICT
I've asked the question on other forums as well yet no one can tell me why I can't get errors even with them enabled.
:-\ Seems I have two problems now..
EDIT: :o Seems it works now. Ugh that frustrating moment when your code suddenly works, but you don't know why..
Still never figured out why I can't get errors though.
-
Yeah I'm writing the file to the same directory as the php script. Which is in my home folder. And I have that folder set as the open_basedir and it's worked fine up until now. As for writing the error it brings me back to an old problem. I can't get any errors. I've made thoroughly sure that I enabled all errors in the php.ini too.
error_reporting
error_reporting E_ERROR E_WARNING E_PARSE
Default Value: E_ALL E_NOTICE E_STRICT E_DEPRECATED
Development Value: E_ALL
Production Value: E_ALL E_DEPRECATED E_STRICT
I've asked the question on other forums as well yet no one can tell me why I can't get errors even with them enabled.
:-\ Seems I have two problems now..
EDIT: :o Seems it works now. Ugh that frustrating moment when your code suddenly works, but you don't know why..
Still never figured out why I can't get errors though.
did you also turn error report on in php.ini ?
think its named php-error
display_errors = On
html_errors = On
error_reporting = E_ALL | E_STRICT
and yeah check the whole file some stuff are there twice
try the
ignore_repeated_errors = On
on also :/
else how did you install the server?
ill usually install everything with
sudo apt-get install tasksel phpmyadmin
-
I'll do more checking through the php.ini. Perhaps I missed something. I installed everything with:
pacman -S apache php php-apache mysql.
Otherwise I have no clue. It seems I have to check /etc/php/php.ini more thoroughly.
-
If you are trying to get this program to run and you are having errors, you might want to check that you have granted your PHP file access to write information to the hard drive. Setting permissions is most often done with the use of an FTP program to execute a command called CHMOD. Use CHMOD to allow the PHP file to write to disk, thus allowing it to create a file.
Have you allowed your php file write access to the hard drive?
This might help:
you should make sure that the apache user (the exact user name will depend on your setup - often httpd or www-data under Linux) has write access to the directory. You can change the owner to the same user as apache (using chown) and set give the owner write access (e.g. "chmod 755") or you can make it world writable (e.g. "chmod 777")
-
Thanks for the help ca0s, relax, skidiot.h, and geXXos. Original issue has been solved.
-
Thanks for the help ca0s, relax, skidiot.h, and geXXos. Original issue has been solved.
How so that way we know :P
-
UPDATE: I just realized how to fix this problem because the issue came up again with a new file. Sorry geXXos I misunderstood what you were trying to say.
I put this:
chmod($myFile, 0777);
In the .php file and it worked. Once again sorry for skimming over your advice geXXos. This is a working solution to this problem for future people.
-
Nice bro that you solved the issue you had,my fault that i wasn't more clear.