Jump to content

[SOLVED] fwrite, save file in my folder, how to change location?


homer.favenir

Recommended Posts

hi to all,

i made my script working very fine and it reads a file and write it down to a new txt file,

but the problem is when my someone uses the program it didnt save in their directory,

but in my directory, even if he specifies the location or i hardcoded the location.

it always saves in my directory.

 

how can i make it saves to their directory.

 

my script:

<html>
<head>
<title></title>
</head>
<body>
<?php
function compare_write($str1, $str2)
{
	$count = 0;
	$dir = 'C:\Documents and Settings\All Users\Desktop\portfoliocompare\\';
	$file = $_POST['newFile'];
	$file = $dir . $file . ".txt";
	if(file_exists($file))
		{?>
			<table border=0>
			<tr>
			<td>
			<h2><font color="#FF0000">Warning! </font>File Already Exist. Pls Rename</h2>
			</td>
			</tr>
			</table>
		<?php }else{

	$file = trim($file);
	$file = fopen($file, 'w');
	$diff = array_diff($str1, $str2);

	foreach($diff as $key => $line)
	{
		echo $line . "<br>";
		fwrite($file, $line);
		$count++;
	}
	echo $count . " " . "Records found";
	}
}
?>
</body>
</html>

 

 

please advice.

 

thanks

 

You want to save it to the client's machine? You'll have to offer it as a download.

 

As GingerRobot said, you need to make offer the file as a download.  PHP is a server side language so cannot do anything to a client machine.

You want to save it to the client's machine? You'll have to offer it as a download.

 

As GingerRobot said, you need to make offer the file as a download.  PHP is a server side language so cannot do anything to a client machine.

 

wait are you trying to get it to dl to his computer or to a directory on the web

from the looks its a directory on a computer, in that case yeah what everyone else said otherwise we have other solutions for web

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.