本文介紹了PHP 文件上傳不讀取 $_FILES['image']的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我有這個輸入類型
<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']
而是移動到其他部分.為什么它不讀取 $_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?
推薦答案
在表單標簽中添加這段代碼enctype="multipart/form-data"
add this code in form tag
enctype="multipart/form-data"
<form action="upload.php" method="post" enctype="multipart/form-data">
這篇關于PHP 文件上傳不讀取 $_FILES['image']的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!