Page 1 of 1

problem in file opening

Posted: Wed Jul 19, 2006 10:14 am
by itsmani1
When i use this code :

Code: Select all

define('OFFERS_DONT_SHOW_NEW',1); 
require "./auth.php"; 
global $my_xcart_url; 



   $myFile = "testFile.txt"; 
   echo $_SERVER['DOCUMENT_ROOT']; 
   $fh = fopen($myFile, 'w+') or die("can't open file"); 

    $str = "";
i get following error

Error:
/home/digiqui/public_html
Warning: fopen(testFile.txt): failed to open stream: Permission denied in /home/digiqui/public_html/test.php on line 10
can't open file

Please help if possible
thanks

Posted: Wed Jul 19, 2006 10:18 am
by Burrito
have write permissions to the file do you?

Posted: Wed Jul 19, 2006 10:20 am
by Luke
open an FTP app and look at the permissions on that file...

Posted: Wed Jul 19, 2006 10:31 am
by itsmani1

Code: Select all

<?
define('OFFERS_DONT_SHOW_NEW',1);
require "./auth.php";
global $my_xcart_url;



	$myFile = "testFile.txt";
	echo $_SERVER['DOCUMENT_ROOT'];
	$fh = fopen($myFile, 'w+') or die("can't open file");

    $str = "";
	$res = mysql_query("SELECT `login`, `firstname`, `lastname`, `email`, `b_address`, `b_city` FROM `xcart_customers` where usertype = 'C' ") or die(mysql_error());
	while($row = mysql_fetch_object($res))
	{
		$stringData = $row -> login.",".$row -> firstname.",".$row -> email.",".$row -> b_address.",".b_city."\n";
		$str .= $stringData;
	}



	$stringData = $str;
	fwrite($fh, $stringData);
	$fname = "testFile.txt";

	header("HTTP/1.1 200 OK");
	header("Content-Type: application/force-download");
	header("Content-Disposition: attachment; filename=$fname");
	header("Content-Transfer-Encoding: binary");
	echo readfile('testFile.txt');


?>
for the above code after changing right got following error :

/home/digiqui/public_html
Warning: Cannot modify header information - headers already sent by (output started at /home/digiqui/public_html/test.php:9) in /home/digiqui/public_html/test.php on line 26

Warning: Cannot modify header information - headers already sent by (output started at /home/digiqui/public_html/test.php:9) in /home/digiqui/public_html/test.php on line 27

Warning: Cannot modify header information - headers already sent by (output started at /home/digiqui/public_html/test.php:9) in /home/digiqui/public_html/test.php on line 28

Warning: Cannot modify header information - headers already sent by (output started at /home/digiqui/public_html/test.php:9) in /home/digiqui/public_html/test.php on line 29

Posted: Wed Jul 19, 2006 10:37 am
by Burrito
fix the permissions issue did you?

if not, then reporting the error it still is, and kill the header() function that will.

Posted: Wed Jul 19, 2006 10:38 am
by JayBird
you need to remove

Code: Select all

echo $_SERVER['DOCUMENT_ROOT'];

Posted: Wed Jul 19, 2006 10:42 am
by itsmani1
Thanks much its working now. One last problme left: its not giving me option where to save it. its opening in IE window i need to get save it on local disc.

for which i added :

Code: Select all

header("HTTP/1.1 200 OK");
	header("Content-Type: application/force-download");
	header("Content-Disposition: attachment; filename=$fname");
	header("Content-Transfer-Encoding: binary");
	echo readfile('testFile.txt');

Posted: Wed Jul 19, 2006 10:49 am
by JayBird
remove echo from this line

Code: Select all

echo readfile('testFile.txt');