Ejemplo n.º 1
0
 /**
  * Get a content of the uploaded file
  *
  * @return string|array Content OR array with errors
  */
 function get_content()
 {
     $input = fopen('php://input', 'rb');
     $temp_file_name = '';
     $temp = open_temp_file($temp_file_name);
     if (is_string($temp)) {
         // Error on create a temp file
         return array('text' => $temp, 'status' => 'error');
     }
     stream_copy_to_stream($input, $temp);
     fclose($input);
     fseek($temp, 0, SEEK_SET);
     $contents = '';
     load_funcs('tools/model/_system.funcs.php');
     $memory_limit = system_check_memory_limit();
     while (!feof($temp)) {
         $curr_mem_usage = memory_get_usage(true);
         if ($memory_limit - $curr_mem_usage < 8192) {
             // Don't try to load the next portion of image into the memory because it would cause 'Allowed memory size exhausted' error
             fclose($temp);
             return array('text' => T_('The server (PHP script) has not enough available memory to receive this large file!'), 'status' => 'error');
         }
         $contents .= fread($temp, 8192);
     }
     fclose($temp);
     if (!empty($temp_file_name)) {
         // Unlink the temp file
         @unlink($temp_file_name);
     }
     return $contents;
 }
/**
 * load data infile
 */
function load_data_infile($filename)
{
    list($r_filename, $r_handle) = open_temp_file('r', $filename);
    while (!feof($r_handle)) {
        $sql = fgets($r_handle);
        if ($sql) {
            db_query($sql);
        }
    }
    close_temp_file($filename, $r_handle);
}