本文介紹了PHP 文件上傳不讀取 $_FILES['image']的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時(shí)送ChatGPT賬號(hào)..
我有這個(gè)輸入類型
<input class="btn btn-success" type="file" name="profile_image" style="margin-top:10px; margin-left:20px;"></input>
用戶將從這里添加圖像文件,以及上傳文件的 PHP 代碼
user will add the image file from here, and the PHP code to upload the file
if(isset($_FILES['profile_image']))
{
$image_type = $this->getImageType($_FILES['profile_image']);
if($image_type == 'image')
{
$extension = pathinfo($_FILES['profile_image']['name'], PATHINFO_EXTENSION);
$filename = '123_'.uniqid().'.'.$extension;
move_uploaded_file($_FILES['profile_image']['tmp_name'], '../functions/images/images/'.$filename);
}
}
else
{
$filename = 'default_profile_image.jpg';
}
和 getImageType
public function getImageType($file)
{
$imageMime = getimagesize($file['tmp_name']);
$type = explode('/', $imageMime['mime']);
return $type[0];
}
但它不讀取 $_FILES['profile_image']
而是移動(dòng)到其他部分.為什么它不讀取 $_FILES ?有什么遺漏嗎?
but it does not read $_FILES['profile_image']
and rather moves to else part. why does it not read $_FILES ? is there anything missing?
推薦答案
在表單標(biāo)簽中添加這段代碼enctype="multipart/form-data"
add this code in form tag
enctype="multipart/form-data"
<form action="upload.php" method="post" enctype="multipart/form-data">
這篇關(guān)于PHP 文件上傳不讀取 $_FILES['image']的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!