Home >Backend Development >PHP Tutorial >php图片上传问题

php图片上传问题

WBOY
WBOYOriginal
2016-06-23 14:01:19932browse

这样的代码怎么不能用?

<?php$post=filter_input_array(INPUT_POST,FILTER_SANITIZE_STRING);//赋值一些变量$pic_turn='';$singername=$post['singername'];$alias=$post['alias'];# 图片上传$uptypes=array(    'image/jpg',    'image/jpeg',    'image/png',    'image/pjpeg',    'image/gif',    'image/bmp',    'image/x-png');$max_file_size=2000000;     //上传文件大小限制, 单位BYTE$destination_folder="../adv/"; //上传文件路径# 添加歌手		if ($_SERVER['REQUEST_METHOD'] == 'POST'){    if (!is_uploaded_file($_FILES["upfile"]["tmp_name"]))    //是否存在文件    {		 $pic_val="0"; //没上传图片         exit;    }    $file = $_FILES["upfile"];    if($max_file_size < $file["size"])    //检查文件大小    {        $tips= "文件太大!";        exit;    }    if(!in_array($file["type"], $uptypes))    //检查文件类型    {        $tips= "文件类型不符!".$file["type"];        exit;    }    if(!file_exists($destination_folder))    {        mkdir($destination_folder);    }    $filename=$file["tmp_name"];    $image_size = getimagesize($filename);    $pinfo=pathinfo($file["name"]);    $ftype=$pinfo['extension'];    $destination = $destination_folder.time().".".$ftype;    if (file_exists($destination) && $overwrite != true)    {        $tips= "同名文件已经存在了";        exit;    }    $pinfo=pathinfo($destination);    $fname=$pinfo[basename];	$pic_turn='<ul class="echo_ok"><p class="ok_win"><b>√</b>添加完成</p><li class="pic"><img  src="about:blank"/ alt="php图片上传问题" ></li><li><p><br>歌手:'.$singername.'</p><p><br>别名:'.$alias.'</p><br><br><p>头像属性<br>文件名:'.$destination_folder.$fname.'<br>宽度:'.$image_size[0].'<br>长度:'.$image_size[1].'<br>大小:'.$file["size"].'bytes</p></li></ul>';}include('assets/singerAdd.html');?>



<form name="addsinger" action="singerAdd.php" method="post" onsubmit="return Checkpost();">    	<p id="tips_msg">  </p>    	<p class="pinfo">        	<label class="items"><span class="fred">*</span>歌手名称:</label>			<input type="text" name="singername" class="ins" value="" >        </p>         <p class="pinfo">        	<label class="items">别名</label>			<input type="text" name="alias" class="ins" maxlength="20" value="" >        </p>        <p class="pinfo">        	<label class="items">歌手头像</label>			<input name="upfile" type="file" onchange="img.src=this.value"> 图片长宽为:150&times;150; 格式为: .jpg        </p>        <p class="pinfo">        	<label class="items"> </label>			<img  src="about:blank" name="image" border=0  id="img"/ alt="php图片上传问题" >        </p>        <p class="pinfo"   style="max-width:90%">			<button type="submit" class="btns">保 存</button>        </p>	</form>


回复讨论(解决方案)

表单中加:enctype="multipart/form-data"
太粗心了哈

表单中加:enctype="multipart/form-data"
太粗心了哈

- - 低级小白   低级错误

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn