25000000) { //echo "Sorry, your file is too large."; $uploadOk = 0; $displayMsg = "Upload Failed: File larger than 25MB"; } // Allow certain file formats if($imageFileType == "php") { $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { //echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file //$displayMsg = "Sorry, your file was not uploaded. (Maybe file already exists / Not allowed format / file larger than 25MB)"; } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { //echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; $filename = $_FILES["fileToUpload"]["name"]; $displayMsg = "Upload Succeed"; } else { $displayMsg = "Upload Failed: Internal Server Error"; //echo "Sorry, there was an error uploading your file."; } } if ($filename != ""){ //DONE $memodir = "Memo/"; $content = "data:file/" . $filename; $content = bin2hex($content); $max = 0; foreach (new DirectoryIterator($memodir) as $fileInfo) { if ($fileInfo->isDot()) continue; $current = pathinfo($fileInfo->getFilename())['filename']; if (!is_numeric($current)) continue; if ($current > $max) $max = $current; } //Check if the number of files exceed the max if ($max > 1000){ foreach (new DirectoryIterator($memodir) as $fileInfo) { $current = pathinfo($fileInfo->getFilename())['filename']; if (!is_numeric($current)) continue; if ((int)$current != 0){ unlink($memodir . $current . ".txt"); } } $max = 0; } $filename = (int)$max + 1; $myfile = fopen($memodir . $filename . ".txt", "w") or die("Unable to open file!"); $txt = $content; fwrite($myfile, $txt); fclose($myfile); //echo $filename; if ($jsonReply == true){ if ($uploadOk == 0){ header('Content-Type: application/json'); echo json_encode(-1); }else{ header('Content-Type: application/json'); echo json_encode($filename); } exit(); } }else{ if ($jsonReply == true){ if ($uploadOk == 0){ echo json_encode("Upload Failed: File already exists / Not allowed format / file larger than 25MB"); } exit(); } } ?>