[英]php - File Upload returns blank page
我編寫了以下代碼,該代碼應驗證用戶上傳的圖像。 但是,運行代碼時,它將返回空白頁。 這是我的代碼:
HTML ( <form>
標題):
<form class="registerbodysections" enctype="multipart/form-data" method="post" action="php/registrationForm.php">
PHP的 :
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$confirmemail = $_POST['confirmemail'];
$birthday = $_POST['birthday'];
$birthmonth = $POST['birthmonth'];
$birthyear = $_POST['birthyear'];
$location = $_POST['location'];
$picture = $_FILES['picture'];
$picturelocation = "../img/uploads/'$email'/picture/'$picture[\'type\']";
echo var_dump($picture); //for testing purposes, but does not get executed
function imageFormatCheck ($fileMime) {
$datatypes = array(
'image/jpg',
'image/gif',
'image/png',
'image/jpeg'
);
foreach($datatypes as $datatype) {
if ($fileMime !== $datatype) {
return false;
}
}
return true;
}
function checkFileType() {
if(imageFormatCheck($fileMime)) {
header('Location: http://google.com');
exit();
} else {
header('Location: http://facebook.com');
exit();
}
}
function moveFile() {
if(!move_uploaded_file($tmpName, $picturelocation)) {
header('Location: http://google.com');
exit();
} else {
header('Location: http://facebook.com');
exit();
}
}
if(count($picture)) {
$tmpName = $picture['tmp_name']; //when I var_dump $picture I receive a single array, not a double array as often seen
$fInfo = $finfo_open(FILEINFO_MIME_TYPE);
$fileMime = finfo_file($fInfo, $tmpName);
$finfo_close($fInfo);
checkFileType();
moveFile();
}
$userDataArray = array(
$firstname,
$lastname,
$birthday,
$birthmonth,
$birthyear,
$location,
$picturelocation
);
?>
我添加了標頭用於測試目的。 但是,這些都沒有被執行。 相反,如上所述,每次都顯示一個空白頁。 HTML <form>
元素是正確的,這就是為什么我不在此處包括它們。 有什么想法可以解決問題嗎? 提前致謝!
注意:目錄$picturelocation
實際上並不存在。 如果move_uploaded_file()
不存在,它是否可以動態創建? 在文檔中找不到任何相關內容。
可從超級全局$ _FILES獲得文件信息。因此,您可以從以下列表中獲取名稱,類型,大小和文件的信息。
$_FILES['userfile']['name']
$_FILES['userfile']['type']
$_FILES['userfile']['size']
$_FILES['userfile']['tmp_name']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.