Guest User

Untitled

a guest
Jan 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. <?php
  2.  
  3. //full name of our file (unparsed)
  4. //$file_name = basename( $_FILES['uploadedfile']['name']);
  5. $file_name = "358718666768940_1301356566"; //uniqueID_posixTime (TESTING PURPOSE)
  6.  
  7. // unique ID of filename (parsed) with positive limit
  8. $unique_ID = explode('_', $file_name);
  9.  
  10. //unique_ID[0] contains 358718666768940
  11. $dirname = $unique_ID[0];
  12. $filename = "csv_history/{$dirname}";
  13. $target_path = "csv_history/{$dirname}/{$unique_ID[1]}"; //temporary (testing purpose)
  14. //NOTE: unique_ID[1]=posix time (1301356566)
  15. //check to see if directory exists, if not create one
  16. if (file_exists($filename))
  17. {
  18. echo "The directory {$dirname} exists!\n";
  19. }
  20. else
  21. {
  22. mkdir("csv_history/{$dirname}", 0777);
  23. echo "The directory {$dirname} was successfully created.\n";
  24. }
  25. // now that the directory is created (or already exists), move the file from temporary storage to the server
  26. if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
  27. {
  28. echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
  29. chmod ("csv_history/{$dirname}/{$unique_ID[1]}", 0644);
  30.  
  31. $headername = "csv_history/{$dirname}/{$dirname} . '.phead'"; // will create a file named 358718666768940.phead
  32. // cont.. path = csv_history/358718666768940/358718666768940.phead
  33. $fh = fopen($headername, "a+");
  34. if ($fh==false)
  35. die("Unable to create or open file.");
  36. fwrite($fh,$unique_ID[1]); //append posix time (1301356566) to file
  37. echo "Success, {$unique_ID[1]} was added to {$unique_ID[0]}.phead!";
  38. fclose($fh);
  39. }
  40. else
  41. {
  42. echo "There was an error uploading the file, please try again!";
  43. echo "filename: " . basename( $_FILES['uploadedfile']['name']);
  44. echo "target_path: " .$target_path;
  45. }
  46.  
  47. ?>
Add Comment
Please, Sign In to add comment