PHP图片上传 [英] PHP image upload
问题描述
我正在处理用户可以选择上传图片的表单,如果他们没有上传图片,那么我将使用默认图片作为他们的个人资料,但我遇到了一些问题,我想验证图片只有在他们上传的时候,但是现在即使他们没有上传图片我的验证码正在运行而且不让保存下面表格的其余部分是我的代码
I am working on a form where a user have an option to upload an image , if they are not uploading the image then i will use a default image for their profile but i am having some problem with that, i want to validate image only if they are uploading it but right now even if they are not uploading the image my validation code is running and not letting save the rest of the form below is my code
if(isset($_FILES))
{
$imagename = $_FILES['uploadimage']['name'];
$imagetype = $_FILES['uploadimage']['type'];
$imagesize = $_FILES['uploadimage']['size'];
if($imagetype != "image/gif" || $imagetype != "image/jpg" || $imagetype == "image/png" || $imagetype == "image/jpeg")
{
$error = 'Please upload an image with JPG, PNG, GIF';
}
elseif($imagesize > 716800)
{
$error = 'Image Needs to be under 700kb only';
}
else
{
$success = 'Uploaded';
}
即使他们没有上传图片,整个代码也在运行
Even if they are not uploading the image the entire code is running
推荐答案
说实话,不要浪费时间创建自己的图片上传代码,只需使用 class.upload 。
To be honest don't waste your time with creating your own image upload code, simply use class.upload.
这篇关于PHP图片上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!