Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 3.144.117.52
<?php
header("Access-Control-Allow-Origin: *");
header('Content-Type: multipart/form-data');
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With, x-auth-origin, x-auth-token, x-auth-type");
$ds = DIRECTORY_SEPARATOR;
$date = date("dmYhis");
$file_resp = "";
if($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
die();
}
// var_dump($_FILES);
if (0 < $_FILES['file']['error']) {
echo 'Error: ' . $_FILES['file']['error'] . '<br>';
$file_resp = "Failed to upload file!";
} else {
$name = $date . '_' . $_FILES['file']['name'];
$theCount = substr_count($name, '.') - 1; // count how many time the period occurs in the string
$name = preg_replace('/\./', '_', $name, $theCount); // replace all but last one
$name = str_replace('&', 'and', $name);
$file_name = str_replace($_FILES['file']['name'], $name, $_FILES['file']['name']); //
$path = realpath(__DIR__) . $ds . 'upload' . $ds . $file_name;
move_uploaded_file($_FILES['file']['tmp_name'], $path);
}
echo $file_name;
|