オンラインシステムからファイルを保存し、特定の場所に保存したい. C:/myFolder/. そのため、C:/ に myFolder 名がない場合、システムは自動的に検出して C ドライブにフォルダーを作成し、そのフォルダーにファイルを保存します。システムをローカルで試すと、フォルダとファイルを C ドライブに作成できます。
しかし、ファイルをサーバーにアップロードすると、フォルダーはローカルコンピューターではなくサーバー内に作成されました。誰でもこれを解決する方法を教えてもらえますか? ローカル コンピューターにフォルダーを作成し、オンライン システムからそのフォルダーにファイルを保存する方法を教えてください。
以下は、システムがローカルで実行されているときに機能するコードです。
$directory = 'C:/sales/'.$filename.'.txt';
$path_name = 'C:/sales/';
if ( ! is_dir($path_name)) {
mkdir($path_name);
}
if(mysql_num_rows($query))
{
$fp = fopen($directory, 'w');
if($fp)
{
for($i = 0; $i < mysql_num_rows($query); $i++)
{
$f = mysql_fetch_array($query);
$orderFee_q = mysql_query("select * from sales_order where status in ('waiting', 'waiting1', 'waiting2', 'approved') and outstanding = 'N' order by so_no desc");
$get_orderFee = mysql_fetch_array($orderFee_q);
$line = $f["id"]."\t".$f["so_no"];
if(trim($line) != '') {fputs($fp, $line."\r\n");}
}
}
fclose($fp);
}
$download_name = basename($filename);
if(file_exists($filename))
{
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Transfer-Encoding: Binary');
header("Content-Disposition: attachment; filename=".$download_name);
header('X-SendFile: '.$filename);
header('Pragma: no-cache');
header("Expires: 0");
readfile($filename);
}