(我也需要幫助才能找到更好的標題,但我不知道如何制定它)
我會有一些問題解釋我需要做什么,因為這很難。基本上我正在制作一個監控系統,我從 curl 命令獲取日志檔案:
curl -F 'file=@/home/jbaudoux/logbackup-infitarif (3).gz' http://pc-arnaud/projet/index.php?customer=exemple
我的腳本將獲取 .gz 檔案,將其從 tmp 移動到由 php 檔案 C://tmplog/exemple 創建的檔案夾,然后解壓縮。
但我認為我做得太難了,做了兩次作業。讓我告訴你我的代碼:
$tmpFilePath = $_FILES["file"]["tmp_name"];
$buffer_size = 8192;
$out_file_path = $folderPath ."\\" .$_FILES["file"]["name"];
$compressedFile = gzopen($tmpFilePath, 'rb');
$out_file = fopen($out_file_path, 'wb');
if($compressedFile != false)
{
while (!gzeof($compressedFile)){
fwrite($out_file, gzread($compressedFile, $buffer_size));
}
}
else{
print("Attention probleme file false");
}
fclose($out_file);
gzclose($compressedFile);
$source_file_path = $folderPath ."\\" .$_FILES["file"]["name"];
$buffer_size = 4096;
$out_file_path = str_replace('.gz', '', $source_file_path);
$file = gzopen($source_file_path, 'rb');
$out_file = fopen($out_file_path, 'wb');
$file_as_text = "";
while(!gzeof($file)) {
$tmp_read = gzread($file, $buffer_size);
fwrite($out_file, $tmp_read);
}
fclose($out_file);
gzclose($file);
你有看到?我做這件事兩次。知道如何在不這樣做兩次的情況下使其作業嗎?但愿如此。
謝謝您的幫助!:)
uj5u.com熱心網友回復:
應該做這樣的事情:
$importantpath = $folderPath ."\\" .$_FILES["file"]["name"];
//copie le fichier compressé
$tmpFilePath = $_FILES["file"]["tmp_name"];
$buffer_size = 8192;
$out_file_path = $importantpath;
$compressedFile = gzopen($tmpFilePath, 'rb');
$out_file_pathe = str_replace('.gz', '', $out_file_path);
$out_file = fopen($out_file_pathe, 'wb');
$file = gzopen($out_file_pathe, 'rb');
$out_filee = fopen($out_file_pathe, 'wb');
$file_as_text = "";
if($compressedFile != false)
{
while (!gzeof($compressedFile)){
fwrite($out_file, gzread($compressedFile, $buffer_size));
$tmp_read = gzread($file, $buffer_size);
fwrite($out_filee, $tmp_read);
}
}
else{
print("Attention probleme file false");
}
fclose($out_file);
fclose($out_filee);
gzclose($compressedFile);
gzclose($file);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/508280.html