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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.