Home > OS >  Undefined variable cannot be solved (Using CURL and Linux)
Undefined variable cannot be solved (Using CURL and Linux)

Time:09-12

I'm trying to make a script work which is going to be used as a monitoring system, but I got a problem Error saying:

Notice: Undefined variable: keep_for_later line 47

but this variable is set line 39.

Any idea?

Here is my php:

<?php
print_r($_FILES["file"]);
$file_name = $_FILES["file"]["tmp_name"];

$buffer_size = 4096;
$out_file_name = str_replace('gz', '', $file_name);

$file = gzopen($file_name, 'rb');
$out_file = fopen($out_file_name, 'wb');

if($file != false)
{
    while (!gzeof($file)){
        fwrite($out_file, gzread($file, $buffer_size));
    }
}
else{
    print("Attention problem file false");
}


fclose($out_file);
gzclose($file);

// $_FILES["file"]["name"]

if (unlink("C:\\tmplog\\".$_FILES["file"]["name"]. "/user.log")) {
    // file was successfully deleted
  } else {
    // there was a problem deleting the file
  }
  sleep(2);
  $find_str = 'total size is';
  $fp = @fopen($_FILES["file"]["tmp_name"], "r");
  if ($fp) {
      while (($line = fgets($fp,)) !== false) {
          if ( strpos($line, $find_str) !== false ) {
              $keep_for_later = $line;
          }
      }
      fclose($fp);
  }



print($keep_for_later);
if (!file_exists('C:\tmplog')) {
    mkdir('C:\tmplog', 0755, true);
}

if (!file_exists("C:\\tmplog\\".$_FILES["file"]["name"])) {
    mkdir("C:\\tmplog\\".$_FILES["file"]["name"], 0755, true);
}

$dir = "C:\\tmplog\\".$_FILES["file"]["name"];
file_put_contents($dir ."/user.log", $keep_for_later);




$array = array();
$value = preg_match("/(\d*,\d*|\d )/",$keep_for_later, $array);
print_r($array);

if($array){
    $teste = $array[0];
    $testa = str_replace(',','', $teste);
    if(is_numeric($teste)){
        $teste = $testa;
    }
    
    
    if ($testa >0) {
        print("Succes: la taille du fichier est de: " .$array[0]);
    }
    else if ($testa == 0) {
        print("Error");
    }
    else{
        print("Warning: the size is: " .$array[0]);
    }
}
else
{

}


$dir = "C:\\tmplog\\".$_FILES["file"]["name"];
file_put_contents($dir ."/result.log", $array);

I got the file from a Curl command:

curl -F '[email protected]'  http://mylink/projet/index.php

Which is run on Linux.

Any idea? Thanks if so!

CodePudding user response:

That is saying the total size is was not found.
Is the case correct? Like is Total capitalized?
strpos is case sensitive. stripos is not.

Set $keep_for_later to a value above the unlink line.

$keep_for_later = 'Not Found';
if (unlink("C:\\tmplog\\".$_FILES["file"]["name"]. "/user.log")) {
  • Related