problem in file opening

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

problem in file opening

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

have write permissions to the file do you?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

open an FTP app and look at the permissions on that file...
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

fix the permissions issue did you?

if not, then reporting the error it still is, and kill the header() function that will.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

you need to remove

Code: Select all

echo $_SERVER['DOCUMENT_ROOT'];
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post 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');
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

remove echo from this line

Code: Select all

echo readfile('testFile.txt');
Post Reply