Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Config
- **/
- $uploadFolder ='./../dare.ga/public_html/qip-shots';
- $uploadPublic = 'http://dare.ga/qip-shots';
- /**
- * Fix multidimentional _FILES array values
- * @param array $_files
- * @return array
- */
- if (!empty($_FILES)) {
- function fix_upload_files_array(array $_files) {
- $files = array();
- foreach ($_files as $name => $file) {
- if (isset($file['name']) && is_array($file['name'])) {
- foreach (array_keys($file['name']) as $key) {
- $files[$name][$key] = array(
- 'name' => $file['name'][$key],
- 'type' => $file['type'][$key],
- 'tmp_name' => $file['tmp_name'][$key],
- 'error' => $file['error'][$key],
- 'size' => $file['size'][$key],
- );
- $files[$name] = fix_upload_files_array($files[$name]);
- }
- } else {
- $files[$name] = $file;
- }
- }
- return $files;
- }
- $_FILES = fix_upload_files_array($_FILES);
- }
- /**
- * Upload file here
- **/
- if (
- isset($_REQUEST['act']) &&
- isset($_FILES['files'][0]) &&
- (int)$_FILES['files'][0]['error'] == 0
- ){
- list($type, $ext) = explode('/', $_FILES['files'][0]['type']); // image/png image/jpeg image/gif
- if (
- $type === 'image' && // check
- in_array($ext, array('png', 'jpeg', 'gif')) && // mime
- getimagesize($_FILES['files'][0]['tmp_name']) !== FALSE // try 2 load as image
- ){
- $hash = md5_file($_FILES['files'][0]['tmp_name']);
- // hash2path
- $path = preg_replace('#^(\w{3})(\w{3})(\w{3})(.+)$#Ui', '$1/$2/$3/$4', "$hash.$ext");
- // Make dir if not exists
- $dir = dirname("$uploadFolder/$path");
- if (!is_dir($dir)){
- mkdir($dir, 0777, true);
- }
- if (move_uploaded_file($_FILES['files'][0]['tmp_name'], "$uploadFolder/$path")){
- echo " ";
- echo "$uploadPublic/$path\n";
- echo "$uploadPublic/$path\n";
- echo "$uploadPublic/delete/?hash=$hash\n";
- echo "$uploadPublic/$path\n";
- file_put_contents('history.txt', implode(';', array(
- date('Y-m-d H:i:s'), // date,
- "$uploadFolder/$path", // local path,
- "$uploadPublic/$path", // web path
- "$type/$ext",
- $_SERVER['REMOTE_ADDR']
- )) . "\r\n", FILE_APPEND);
- die();
- }
- }
- }
- die("\r\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement