Dear friends, Iam newbe to this forum. I am a php developer. But now I am working with files. I am using fopen("file.txt","r"); This is not working for me. The safe mode is on. and open_basedir is not set and I tried with the "file_exists" command to check if the file is there or not , That is working fine and file exists. But I am not able to open that file for reading Pleae help me Thanks in advance Shino
Have you checked the file permissions on the file you are trying to read? Getting any error messages or notices?
Have you tried the is_readable function? That should tell you if you can open for reading or not. Also, what error does it print when you try to open the file. What version of PHP are you using and on what OS?
ssh in and chmod 755 the file you are trying to open. You can verify permissions by typing ls -l filename mike
All of the above applies. Plus, all you have said is it's not working for you. Without seeing the real code, we may never know if the problem lies therein.
$file = "./test.txt"; if(is_readable($file)) { echo "readable"; } else { echo "not readable"; } if($fp = fopen($file,"r")) { while ($data = fread($fp,4096)) { echo "-----".$data; } } This is the code I am uning and is_readable is telling readable But file is not opening I am using windows OS Thanks shino
Have you tried without the ./ infront of the file name? Or perhaps try the absolute path to the file? (ie c:/mydir/myfile ) Also, try the b flag. fopen($file,"rb").
When I tested it, I tested absolute path, relative path, and with the ./ and all three worked for me, so I think his problem is elsewhere. Shino, try calling clearstatcache before your code and see what happens.
file_get_contents command is working for me I tried like this too; clearstatcache(); $fp = fopen("text.txt","rb") or die("No Ya"); echo "Opened "; but the same result It is godaddy server. and is windows system.