Рубрики
Uncategorized

Обзор знаний, связанных с загрузкой файлов PHP

Автор оригинала: David Wong.

В настоящее время ведутся последние обзоры загрузок файлов PHP. Вот запись.

php
date_default_timezone_set('PRC');
if(isset($_POST['submit'])) {
    echo "
";
    var_dump($_FILES['file']);
    echo "
"; // Method 1 for obtaining file suffix names: // Divide file names into arrays with "." as a boundary // For an array, the end function takes the last element in the array. $ext = end(explode(".", $_FILES['file']['name'])); // Method 2 for obtaining file suffix names: // Find the location of the point in the file name and intercept the string after that location //$extpos = strrpos($_FILES['file']['name'],'.'); //$ext = substr($_FILES['file']['name'], $extpos+1); // echo: "File suffix is:" $ext; // Setting Uploadable File Types $allowType = [ "gif", "jpeg", "jpg", "png" ]; // Check if uploaded files are supported if (!in_array($ext, $allowType)) { Die ("please choose the correct file format to upload"); } else { // Name upload file as year, month, day, time, second $filename = date("YmdHis", time()) . ".".$ext; // Name the upload folder year-month-day and save the files uploaded on the same day $directory = "uploads"."/".date("Y-m-d", time()); // Detecting the existence of the target file directory if (!is_dir($directory)) { // Create folders if they do not exist mkdir ($directory,0777,true); // Save temporary files to the same day directory move_uploaded_file($_FILES['file']['tmp_name'], $directory . "/" . $filename); } else { // Detecting whether the file already exists in the target folder if (!file_exists()) { // Save temporary files to a specified directory if they do not exist move_uploaded_file($_FILES['file']['tmp_name'], $directory . "/" . $filename); }else{ Die ("This file already exists"); } } } } ?> < title > file upload job
Please select the file