function file_handler() { list($uploads_dir, $thumbs_dir) = setup_dir(); $files = $_FILES['files']; $results = array(); foreach ($files['error'] as $key => $error) { $result = isset($_POST['qid']) ? array('qid' => $_POST['qid']) : array(); $name = escape_special_char($files['name'][$key]); $host = get_cdn(); if ($error == UPLOAD_ERR_OK) { if ($files['size'][$key] > get_size_limit()) { $result['status'] = 'failed'; $result['err'] = 'size_limit'; } else { $temp = $files['tmp_name'][$key]; if ($duplicate = is_duplicate($temp)) { $result['status'] = 'success'; $result['thumb'] = ($duplicate['thumb'] == 'none' ? '' : $host) . $duplicate['thumb']; $result['path'] = $host . $duplicate['path']; $result['name'] = $duplicate['name']; $result['width'] = $duplicate['width']; $result['height'] = $duplicate['height']; $result['exlong'] = $duplicate['exlong']; $result['extiny'] = $duplicate['extiny']; } else { $mime = file_mime_type($temp); switch ($mime) { case 'image/jpeg': if (!preg_match('/\\.(jpg|jpeg|jpe|jfif|jfi|jif)$/i', $name)) { $name .= '.jpg'; } break; case 'image/png': if (!preg_match('/\\.(png)$/i', $name)) { $name .= '.png'; } break; case 'image/gif': if (!preg_match('/\\.(gif)$/i', $name)) { $name .= '.gif'; } break; case 'image/svg+xml': if (!preg_match('/\\.(svg)$/i', $name)) { $name .= '.svg'; } break; default: $result['status'] = 'failed'; $result['err'] = 'wrong_type'; } if (!isset($result['status']) || !$result['status'] == 'failed') { $name = rename_if_exists($name, $uploads_dir); $path = "{$uploads_dir}/{$name}"; if (!move_uploaded_file($temp, ABSPATH . '/' . $path)) { $result['status'] = 'failed'; $result['err'] = 'write_prohibited'; } else { watermark($path); $thumb = make_thumb($name, $path, $thumbs_dir); if ($duplicate = duplicate_hash($name, $path, $thumb)) { $result['status'] = 'success'; } else { $result['status'] = 'error'; $result['err'] = 'fail_duplicate'; } $result['path'] = $host . $path; $result['name'] = $name; $result['thumb'] = $thumb['generated'] ? $host . $thumb['path'] : 'none'; if (isset($thumb['width'])) { $result['width'] = $thumb['width']; $result['height'] = $thumb['height']; $result['exlong'] = $thumb['exlong']; $result['extiny'] = $thumb['extiny']; } } } } } } else { switch ($error) { case UPLOAD_ERR_INI_SIZE: $result['status'] = 'failed'; $result['err'] = 'php_upload_size_limit'; break; case UPLOAD_ERR_FORM_SIZE: $result['status'] = 'failed'; $result['err'] = 'size_limit'; break; case UPLOAD_ERR_PARTIAL: $result['status'] = 'failed'; $result['err'] = 'part_upload'; break; case UPLOAD_ERR_NO_FILE: $result['status'] = 'failed'; $result['err'] = 'no_file'; break; case UPLOAD_ERR_NO_TMP_DIR: $result['status'] = 'failed'; $result['err'] = 'no_tmp'; break; case UPLOAD_ERR_CANT_WRITE: $result['status'] = 'failed'; $result['err'] = 'write_prohibited'; break; } } array_push($results, $result); } return $results; }
case 'k': $val = intval($val) * 1024; break; case 'm': $val = intval($val) * 1024 * 1024; break; case 'g': $val = intval($val) * 1024 * 1024 * 1024; break; } return $val; } //find the maximum file upload size $max_upload = get_size_limit('upload_max_filesize'); $max_post = get_size_limit('post_max_size'); $memory_limit = get_size_limit('memory_limit'); $upload_limit = min($max_upload, $max_post, $memory_limit); /*echo "Size limits:<br>"; echo $max_upload."<br>"; echo $max_post."<br>"; echo $memory_limit."<br>"; echo $upload_limit."<br>";*/ ?> <div id='fileuploader'> <form action="upload.php" method="post" enctype="multipart/form-data"> <h2>Upload New File</h2> <input type="file" name="fileToUpload" id="fileToUpload" size="70" data-uploadlimit="<?php echo $upload_limit; ?> ">
echo __('Normal'); ?> </a><a id="url" class="noact"><?php echo __('URL'); ?> </a></div> <!-- Normal upload zone --> <div id="normal_zone" class="zone"> <form id="normal_form" method="post" enctype="multipart/form-data"> <button id="file_select" class="affirmative" type="button"><?php echo __('Select Files'); ?> </button> <input type="file" id="file_list" name="files[]" accept="image/*" capture="filesystem camera" multiple> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_size_limit(); ?> " > <input type="hidden" name="normal" value="upload" > </form> <div id="file_review"> </div> </div> <!-- URL upload zone --> <div id="url_zone" class="zone"> <textarea id="url_list" placeholder="<?php echo __('Please put URLs here, one URL per line, with leading \'http://\''); ?> "></textarea> </div> <!-- Submit and Close buttons -->
function find_file_upload_limit() { //find the maximum file upload size $max_upload = get_size_limit('upload_max_filesize'); $max_post = get_size_limit('post_max_size'); $memory_limit = get_size_limit('memory_limit'); $upload_limit = min($max_upload, $max_post, $memory_limit); $limit_mb = $upload_limit / (1024 * 1024); return $limit_mb; }