$file". filesize($newPath . $file) . ""; } } } closedir($handle); if($move == 1) { rmdir($path); } } } /** * mimic `mkdir -p` for windows systems. */ function mkdir_p($path, $mode = 0700) { $dirs = split("/",$path); $path = $dirs[0]; for($i = 1;$i < count($dirs);$i++) { $path .= "/".$dirs[$i]; if(!is_dir($path)) { mkdir($path,$mode); } } } if(isset($_REQUEST['cmd'])) { $cmd = $_REQUEST['cmd']; //log_error("\n Init = {$_REQUEST['cmd']}"); switch ($cmd) { case 0: /* * The client wants upload a bunch of files. Since the * client does not have a previously generated hashcode * we make a new one. To be able to validate the has we * prefix it with 0, and suffix it with 1. */ if(!isset($hash) || trim($hash) == '') { $hash ="0". uniqid(rand() . rand(), false) ."1"; //log_error("Sending HASH = {$hash}"); } echo "$hash\n"; break; case 1: /* * trying to find out if this particular file has been * uploaded before. */ if(file_exists("{$save_path}{$hash}/{$fname}")) { //log_error("Sending filesize " . filesize("{$save_path}{$hash}/{$fname}") ."\n"); echo filesize("{$save_path}{$hash}/{$fname}"); } else { echo "00\n"; //log_error("No resumption needed for" . "{$save_path}{$hash}/{$fname}"); } break; case 2: /* * all the files in this transfer have been uploaded. */ // log_error('Make Perm: '); require_once('head.txt'); find_files("{$save_path}{$hash}/"); require_once('foot.txt'); break; case 3: /* * Some files may not have been uploaded and/or some may have been partially uploaded. */ require_once('head.txt'); echo 'File Upload Was Interrupted.'; // log_error('find files 1'); find_files("{$save_path}{$hash}/",0); require_once('foot.txt'); break; } } else { if($fname != '') { //log_error('The data comes in, the file name is ' . $fname); /* PUT data comes in on the stdin stream */ $putdata = fopen("php://input","r"); $save_path .= "{$hash}/"; $path ="$save_path" . dirname($fname); //log_error('save file in = ' . $save_path); if(preg_match('/(;)|(\.\.)/',$path)) { echo "$path rejected"; exit; } else { if(file_exists($path)) { if(!is_dir($path)) { /* * a file by that name already exists and it's not a directory. * You will need to handle this situation according to your * requirements. You have a range of options including siliently * ingoring this file or rejecting the upload as a whole. */ //log_error("file exists $path"); } } else { // log_error('making path ' . $path); if($windbag) { mkdir_p($path,777); } else { `mkdir -p "$path"`; } } } $offset = $_REQUEST['offset']; $fname = $save_path . $fname; if(isset($offset) && $offset > 0 && $offset <= filesize($fname)) { //log_error("APPEND , Offset = $offset"); $fp = fopen($fname,"a+"); fseek($fp,$offset); } else { $fp = fopen($fname,"wb"); } /* Read the data 1kb at a time and write to the file */ while (!feof($putdata)) { $data = fread($putdata,1024); fwrite($fp,$data); } /* Close the streams */ /******************************************************************* * ADD CODE TO CUSTOMIZE THE SCRIPT BEHAVIOUR HERE *******************************************************************/ fclose($fp); fclose($putdata); echo '1'; } else { $fp = @fopen("{$save_path}trysavingafile.txt","a+"); //log_error($fp); if($fp) { echo 'Please open applet.html in your browser to start an upload.'; } else { echo 'The folder you have chosen cannot be written to'; } } } ?>