File manager - Edit - /home/missmand/public_html/learning/maia/upload.php
Back
<?php header('Content-type: application/json'); // Create function to set http response code. if (!function_exists('http_response_code')) { function http_response_code($newcode = NULL) { static $code = 200; if($newcode !== NULL) { header('X-PHP-Response-Code: '.$newcode, true, $newcode); if(!headers_sent()) $code = $newcode; } return $code; } } if(!isset($_FILES["sound"])) { http_response_code(404); die(); } $error = NULL; $target_dir = "../file/audio/"; $target_filename = time() . '-' . basename($_FILES["sound"]["name"]); $target_file = __DIR__ . '/' . $target_dir . $target_filename; $soundFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if file already exists if (file_exists($target_file)) { $error = "Sorry, file already exists."; } // Check file size 50MB if ($_FILES["sound"]["size"] > 50000000) { $error = "file is too large"; } // Allow certain file formats if($soundFileType != "mp3") { $error = "File format not supported"; } // Check if $uploadOk is set to 0 by an error if ($error != NULL) { http_response_code(500); echo json_encode(array("error"=>$error)); // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["sound"]["tmp_name"], $target_file)) { http_response_code(200); echo json_encode(array("error"=>$error, "file"=> $target_filename)); } else { http_response_code(500); echo json_encode(array("error"=>'Error while uploading the file')); } } ?>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings