<form action="send.php" enctype="multipart/form-data"><input type="file" name="var-trigger"></form>
PHP創建陣列稱爲$ _FILES
條目在這種情況下$ _FILES [ '無功觸發']
使用名稱從形式這個排列U具有$ _FILES [在此之後第二陣列旁'VAR-觸發']:
$_FILES['var-trigger']['tmp_name']
$_FILES['var-trigger']['name']
$_FILES['var-trigger']['size']
$_FILES['var-trigger']['type'] //text/plain, image/png et cetera
使用如果statment和的preg_match類型:
if (preg_match('/^image\/gif$/i', $_FILES['var-trigger']['type'])) { $ext='gif';}
else if (preg_match('/^image\/(x-)?png$/i', $_FILES['var-trigger']['type'])) { $ext='png';}
if ($ext=='png') {$file_title= 'P'; }
else if ($ext=='gif') {$file_title= 'G'; }
<?php
// integer starts at 0 before counting
$i = 0;
$dir = $ext;
if ($handle = opendir($dir)) {
while (($file = readdir($handle)) !== false){
if (!in_array($file, array('.', '..')) && !is_dir($dir.$file))
$i++;
}
}
// prints out how many were in the directory
echo "There were $i files";
?>
$filename = 'direction'. $file_title . $i . time() . $SERVER['REMOTE_ADDR'] . $ext;
if(!is_uploaded_file($_FILES['var-trigger']['tmp_name']) or !copy($_FILES['var-trigger']['tmp_name'],$filename)) { echo 'error'; exit(); }
$ SERVER [ 'REMOTE_ADDR'],以避免Count how many files in directory php
上傳2個文件就在同一時期
目錄代碼!is_upload_file線是防止惡意文件使用FILNAME喜歡的/ etc/