lamiastella

upload.php

Sep 26th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.92 KB | None | 0 0
  1. <?php
  2. $target_dir = "uploads/";
  3. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  4. $uploadOk = 1;
  5. $fileType = pathinfo($target_file, PATHINFO_EXTENSION);
  6. // Check if image file is a actual image or fake image
  7. if(isset($_POST["submit"])) {
  8.     //$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  9.     $check = filesize($_FILES["fileToUpload"]["tmp_name"]);
  10.     if($check !== false) {
  11.         echo "This is a XLS format file - " . $check["mime"] . ".";
  12.         $uploadOk = 1;
  13.     } else {
  14.         echo "This is not a XLS format file.";
  15.         $uploadOk = 0;
  16.     }
  17. }
  18. // Check if file already exists
  19. if (file_exists($target_file)) {
  20.     echo "File already exists! Upload a new file";
  21.     $uploadOk = 0;
  22. }
  23. // Check file size
  24. //check with WonHwa, what size limit are we looking at?
  25. if ($_FILES["fileToUpload"]["size"] > 500000) {
  26.     echo "Sorry, your file is too large.";
  27.     $uploadOk = 0;
  28. }
  29. // Allow certain file formats
  30. if($fileType != "xls" ) {
  31.     echo "Sorry! Only XLS files can be uploaded!!";
  32.     $uploadOk = 0;
  33. }
  34. // Check if $uploadOk is set to 0 by an error
  35. if ($uploadOk == 0) {
  36.     echo "Sorry, your file was not uploaded.";
  37. // if everything is ok, try to upload file
  38. } else {
  39.     if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  40.       //  echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.".shell_exec("head -5 $target_file");
  41.         //  echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.".shell_exec("matlab -nodesktop -nosplash -r  \"main_xls_input($target_file,40, 0.4, 0.01, 0.1, 3); exit\"");
  42.       echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.".shell_exec("matlab -nodesktop -nosplash -r  \"main_xls_input('".$target_file."',40, 0.4, 0.01, 0.1, 3); exit\"");
  43.  
  44.     } else {
  45.         echo "Sorry, there was an error uploading your file.";
  46.     }
  47. }
  48.  
  49. ?>
Add Comment
Please, Sign In to add comment