• Uncategorized

About php : Need-help-unzip-a-tmp-file-and-and-rewite-it-to-another-path

Question Detail

(I also need help to found a better title but i have no idea how to formulate it)

I will have some issue explain what i need to do because it’s pretty hard.
Basicly i’m making a monitoring system, i’m getting the log file from a curl command:

curl -F '[email protected]/home/jbaudoux/logbackup-infitarif (3).gz'  http://pc-arnaud/projet/index.php?customer=exemple

And my script will take the .gz file, move it from the tmp to the a folder made by the php file C://tmplog/exemple and then unzip it.

But i think i’m making it too hard and doing the work twice.
Lemme show you my code:

$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);

Do you see? I’m doing the stuff twice. Any idea of how to made it work wihout doing that’s twice? I hope so.

Thanks for the help! 🙂

Question Answer

No answer for now.

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.