Example #1
0
        $status = array();
    }
    $status['done'] = 1;
    $status['width'] = $size[0];
    $status['url'] = nicupload_file_uri($filename);
    if ($rfc1867) {
        apc_store('upload_' . $id, $status);
    }
    nicupload_output($status, $rfc1867);
    exit;
} else {
    if (isset($_GET['check'])) {
        // Upload progress check
        $check = $_GET['check'];
        if (!is_numeric($check)) {
            nicupload_error('Invalid upload progress id');
        }
        if ($rfc1867) {
            $status = apc_fetch('upload_' . $check);
            if ($status['total'] > 500000 && $status['current'] / $status['total'] < 0.9) {
                // Large file and we are < 90% complete
                $status['interval'] = 3000;
            } else {
                if ($status['total'] > 200000 && $status['current'] / $status['total'] < 0.8) {
                    // Is this a largeish file and we are < 80% complete
                    $status['interval'] = 2000;
                } else {
                    $status['interval'] = 1000;
                }
            }
            nicupload_output($status);
Example #2
0
 function nicUpload()
 {
     $nicupload_allowed_extensions = array('jpg', 'jpeg', 'png', 'gif', 'bmp');
     // You should not need to modify below this line
     $rfc1867 = function_exists('apc_fetch') && ini_get('apc.rfc1867');
     if (!function_exists('json_encode')) {
         die('{"error" : "Image upload host does not have the required dependicies (json_encode/decode)"}');
     }
     $id = $this->input->post('APC_UPLOAD_PROGRESS');
     if (empty($id)) {
         $id = $this->input->get('id');
     }
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         // Upload is complete
         if (empty($id) || !is_numeric($id)) {
             nicupload_error('Invalid Upload ID');
         }
         if (!is_dir(NICUPLOAD_PATH) || !is_writable(NICUPLOAD_PATH)) {
             nicupload_error('Upload directory ' . NICUPLOAD_PATH . ' must exist and have write permissions on the server');
         }
         $file = $_FILES['nicImage'];
         $image = $file['tmp_name'];
         $max_upload_size = $this->ini_max_upload_size();
         if (!$file) {
             $this->nicupload_error('Must be less than ' . $this->bytes_to_readable($max_upload_size));
         }
         $ext = strtolower(substr(strrchr($file['name'], '.'), 1));
         @($size = getimagesize($image));
         if (!$size || !in_array($ext, $nicupload_allowed_extensions)) {
             $this->nicupload_error('Invalid image file, must be a valid image less than ' . $this->bytes_to_readable($max_upload_size));
         }
         $filename = $id . '.' . $ext;
         $path = NICUPLOAD_PATH . '/' . $filename;
         if (!move_uploaded_file($image, $path)) {
             $this->nicupload_error('Server error, failed to move file');
         }
         if ($rfc1867) {
             $status = apc_fetch('upload_' . $id);
         }
         if (!$status) {
             $status = array();
         }
         $status['done'] = 1;
         $status['width'] = $size[0];
         $status['url'] = $this->nicupload_file_uri($filename);
         if ($rfc1867) {
             apc_store('upload_' . $id, $status);
         }
         $this->nicupload_output($status, $rfc1867);
         exit;
     } else {
         if ($this->input->get('check') != '') {
             // Upload progress check
             $check = $this->input->get('check');
             if (!is_numeric($check)) {
                 $this->nicupload_error('Invalid upload progress id');
             }
             if ($rfc1867) {
                 $status = apc_fetch('upload_' . $check);
                 if ($status['total'] > 500000 && $status['current'] / $status['total'] < 0.9) {
                     // Large file and we are < 90% complete
                     $status['interval'] = 3000;
                 } else {
                     if ($status['total'] > 200000 && $status['current'] / $status['total'] < 0.8) {
                         // Is this a largeish file and we are < 80% complete
                         $status['interval'] = 2000;
                     } else {
                         $status['interval'] = 1000;
                     }
                 }
                 $this->nicupload_output($status);
             } else {
                 $status = array();
                 $status['noprogress'] = true;
                 foreach ($nicupload_allowed_extensions as $e) {
                     if (file_exists(NICUPLOAD_PATH . '/' . $check . '.' . $e)) {
                         $ext = $e;
                         break;
                     }
                 }
                 if ($ext) {
                     $status['url'] = $this->nicupload_file_uri($check . '.' . $ext);
                 }
                 $this->nicupload_output($status);
             }
         }
     }
 }