Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //full name of our file (unparsed)
- //$file_name = basename( $_FILES['uploadedfile']['name']);
- $file_name = "358718666768940_1301356566"; //uniqueID_posixTime (TESTING PURPOSE)
- // unique ID of filename (parsed) with positive limit
- $unique_ID = explode('_', $file_name);
- //unique_ID[0] contains 358718666768940
- $dirname = $unique_ID[0];
- $filename = "csv_history/{$dirname}";
- $target_path = "csv_history/{$dirname}/{$unique_ID[1]}"; //temporary (testing purpose)
- //NOTE: unique_ID[1]=posix time (1301356566)
- //check to see if directory exists, if not create one
- if (file_exists($filename))
- {
- echo "The directory {$dirname} exists!\n";
- }
- else
- {
- mkdir("csv_history/{$dirname}", 0777);
- echo "The directory {$dirname} was successfully created.\n";
- }
- // now that the directory is created (or already exists), move the file from temporary storage to the server
- if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
- {
- echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
- chmod ("csv_history/{$dirname}/{$unique_ID[1]}", 0644);
- $headername = "csv_history/{$dirname}/{$dirname} . '.phead'"; // will create a file named 358718666768940.phead
- // cont.. path = csv_history/358718666768940/358718666768940.phead
- $fh = fopen($headername, "a+");
- if ($fh==false)
- die("Unable to create or open file.");
- fwrite($fh,$unique_ID[1]); //append posix time (1301356566) to file
- echo "Success, {$unique_ID[1]} was added to {$unique_ID[0]}.phead!";
- fclose($fh);
- }
- else
- {
- echo "There was an error uploading the file, please try again!";
- echo "filename: " . basename( $_FILES['uploadedfile']['name']);
- echo "target_path: " .$target_path;
- }
- ?>
Add Comment
Please, Sign In to add comment