upload_marks.php 1.83 KB
<?php
sleep(3);
$path = '/wp-content/uploads/marks_imported/';
$targetPath = Tz\DOC_ROOT .$path;
//die($targetPath);


if (!empty($_FILES)) {
   $tempFile = $_FILES['Filedata']['tmp_name'];
   
   
   $filename = $_FILES['Filedata']['name'];
   $ext = substr($filename, strrpos($filename, '.') + 1);
   
   $newfile = md5(time()).".".$ext;
   

   //
   $targetFile =  str_replace('//','/',$targetPath) . $newfile;
   
   // Uncomment the following line if you want to make the directory if it doesn't exist
   // mkdir(str_replace('//','/',$targetPath), 0755, true);
   
   move_uploaded_file($tempFile,$targetFile);
}

switch ($_FILES['Filedata']['error'])
{     
     case 0:
             //$msg = "No Error"; // comment this out if you don't want a message to appear on success.
             break;
     case 1:
              $msg = "The file is bigger than this PHP installation allows";
              break;
      case 2:
              $msg = "The file is bigger than this form allows";
              break;
       case 3:
              $msg = "Only part of the file was uploaded";
              break;
       case 4:
             $msg = "No file was uploaded";
              break;
       case 6:
             $msg = "Missing a temporary folder";
              break;
       case 7:
             $msg = "Failed to write file to disk";
             break;
       case 8:
             $msg = "File upload stopped by extension";
             break;
       default:
            $msg = "unknown error ".$_FILES['Filedata']['error'];
            break;
}

If (isset($msg)) {
    $return = array(
        'success'=>'false'
      , 'msg'=>"Error: ".$_FILES['Filedata']['error']." Error Info: ".$msg
    );
    die(json_encode($return));
} else {

    $return = array(
        'success'=>'true'
      , 'filename'=>$path.$newfile
    );
    die(json_encode($return));
}

?>