Formu kurarken çoktan/form verisi ayarlamalısınız. Daha sonra, formu işlediğinizde, dosyanın dosya adını almak için yükleme dosyasının ve _FILES dosyasının dosya adını almak için _POST'a bakmış olursunuz. Aşağıda, .PDF veya Word docs'ın çok parçalı yüklemelerini işlemek için yazdığım bir uygulama için eski bir kod var. Öncelikle, dosya adının _POST içinde ayarlandığından emin olun, sonra izin verilen bir uzantı içerdiğini kontrol edin, ardından uzantının beklenen MIME türüyle eşleştiğinden emin olun (herhangi bir şeyin yüklenmesine izin vermekten biraz daha güvenli):
if (isset($_POST['File'])) {
if (isset($_FILES['File']['name']['filename'])) {
if (!$_FILES['File']['error']['filename']) {
// Check mime type
$type = $_FILES['File']['type']['filename'];
if ($type != 'application/pdf' && $type != 'application/msword' &&
$type != 'application/vnd.openxmlformats-officedocument.presentationml.presentation') {
echo "<br>Sorry - type: " . $type . " is not supported. ";
die;
}
$fi = finfo_open(FILEINFO_MIME_TYPE);
//verify file infor matches the mime type;
$mime = finfo_file($fi, $_FILES['File']['tmp_name']['filename']);
finfo_close($fi);
if ($mime != $type) {
echo "<br>Sorry this file type: " . $type . " does not match the mime type: " . $mime;
die;
}
// Check that the extension is allowed
$filename = strtolower($_FILES['File']['name']['filename'])
$whitelist = array('pdf', 'doc', 'pptx');
$ext = end(explode('.', $filename));
if (!in_array($ext, $whitelist)) {
echo '\n<br> Sorry file ' . $filename . ' has invalid extension: ' . $ext;
die;
}
// If you made it to here - ok to process file
} else {
// Give back a message for debugging
switch ($_FILES['File']['error']['filename']) {
case 1:
$errMsg = "UPLOAD_ERR_INI_SIZE - Size " . $img->size . " exceeds php.ini upload_max_filesize";
break;
case 2:
$errMsg = "UPLOAD_ERR_FORM_SIZE - Size " . $img->size . " exceeds MAX_FILE_SIZE of HTML form";
break;
case 3:
$errMsg = "UPLOAD_ERR_PARTIAL - File did not complete uploading";
break;
case 4:
$errMsg = "UPLOAD_ERR_NO_FILE - File failed to upload";
break;
case 6:
$errMsg = "UPLOAD_ERR_NO_TMP_DIR - Missing tmp folder ";
break;
case 7:
$errMsg = "UPLOAD_ERR_CANT_WRITE - Failed to write file to disk";
break;
case 8:
$errMsg = "UPLOAD_ERR_EXTENSION - php extenion stopped this file from uploading - check php.ini";
break;
default:
$errMsg = $_FILES['File']['error']['filename'] . " - Unknown error in image upload";
}
echo "File Upload died with errors. " . $errMsg;
die;
}
}
'isset ($ _ DOSYASI)': böyle bir şey işlemek için Ardından
: Form böyle bir şey yapmak? – Jon
, $ _FILES okuyamıyor mu? – MacGyer
Kesintisiz parça verisi gönderebilmenizin tüm yollarından emin değilim, ama biliyorum ki $ _FILES' ** bir **. –