php图片上传问题

php中文网
发布: 2016-06-23 14:01:19
原创
1270人浏览过

这样的代码怎么不能用?

<?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>
                    <div class="aritcle_card">
                        <a class="aritcle_card_img" href="/ai/1500">
                            <img src="https://img.php.cn/upload/ai_manual/000/969/633/68b7a441772f6218.png" alt="Cutout老照片上色">
                        </a>
                        <div class="aritcle_card_info">
                            <a href="/ai/1500">Cutout老照片上色</a>
                            <p>Cutout.Pro推出的黑白图片上色</p>
                            <div class="">
                                <img src="/static/images/card_xiazai.png" alt="Cutout老照片上色">
                                <span>20</span>
                            </div>
                        </div>
                        <a href="/ai/1500" class="aritcle_card_btn">
                            <span>查看详情</span>
                            <img src="/static/images/cardxiayige-3.png" alt="Cutout老照片上色">
                        </a>
                    </div>
                </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"
太粗心了哈

- - 低级小白   低级错误

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号