Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* ===== CONSTANTS ===== */
- $ROOT_DIR = 'FILES';
- $COMPUTER_NAME = 'compname';
- $PROGRAM = 'program';
- $FILENAME = 'file';
- $CHUNK_SIZE = 1024;
- /* ===================== */
- //=====================================
- /**
- Function that gets current time and formats it into pretty looking date
- */
- function makeDate() {
- return strftime('%Y-%m-%d, %H.%M');
- }
- //=====================================
- // check here if the parameters are set. If it's not then it's safe to say some one is snooping around...
- if (isset($_POST[$COMPUTER_NAME], $_POST[$PROGRAM], $_FILES[$FILENAME])) {
- // construct a full path and create it
- $fullPath = $ROOT_DIR.'\\'.$_POST[$COMPUTER_NAME].'\\'.$_POST[$PROGRAM].'\\'.makeDate();
- mkdir($fullPath, 0777, true);
- // move the files and rename them as temporary
- $filename = $_FILES[$FILENAME]['name'];
- move_uploaded_file(($_FILES[$FILENAME]['tmp_name']), $fullPath.'\\'.$filename.'.tmp');
- // decode received files
- $src = fopen($fullPath.'\\'.$filename.'.tmp', 'rb');
- $dst = fopen($fullPath.'\\'.$filename, 'wb');
- while (!feof($src)) {
- fwrite($dst, base64_decode(fread($src, $CHUNK_SIZE)));
- }
- fclose($dst);
- fclose($src);
- unlink($fullPath.'\\'.$filename.'.tmp'); // remove the temp file after decoding it
- echo 'OK!';
- } else {
- echo 'oh no :(';
- }
- //=====================================
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement