图片上传审核PHP源码(php 图片上传)
本文目录一览:
- 1、有没有php动态上传图片的代码。网上大部分都是忽悠人的。只能上传一张。如果符合要求的话分全都给了。谢谢
- 2、PHP上传图片函数源码(重金悬赏)
- 3、php上传图片代码
- 4、菜鸟一只,求PHP批量上传图片的整个代码。
- 5、有没有PHP上传多张图片的源码学习一下
- 6、php上传图片到服务器的前端和php代码
有没有php动态上传图片的代码。网上大部分都是忽悠人的。只能上传一张。如果符合要求的话分全都给了。谢谢
已在百度hi中解决,现附上源码:首先,创建一个upload.html;内容如下:
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; cha$resultet=utf-8" /
title
/title
script language="javascript"
function upload(id){
div = document.getElementById('light');
div.style.display='block';
document.getElementById('fade').style.display='block';
childs = div.childNodes;
for(i=0;ichilds.length;i++){
if(childs[i].nodeName.toUpperCase() == "IFRAME"){
childs[i].src="funs/up.php?label="+id;
}
}
}
//删除元素
function delpic(id){
a = document.getElementById("pics");
child = document.getElementById("span"+id);
a.removeChild(child);
}
//添加元素
function create(id){
span = document.createElement("span");
span.id = "span"+id;
span.style.display = "block";
span.style.height = "22px";
span.style.lineHeight = "22px";
span.innerHTML = "名称: input type='text' name='pic_name[]' id='pic_name"+id +"' size='20'nbspnbsp地址: input type='text' name='pic_url[]' id='pic_url"+id +"' size='30' [a href='javascript:' onClick='upload("+id+")'font color='#FF0000'上传更换图片/font/a] [a href='javascript:delpic("+id+")'移除/a]";
return span;
}
function add_upload(){
div = document.getElementById("pics");
mynum = parseInt(document.getElementById("num").value,10);
//mynum = document.getElementById("num").value;
document.getElementById("num").value = mynum+1;
obj = create(mynum);
div.appendChild(obj);
}
/script
style type="text/css"
.white_content {
display:none;
position:absolute;
width:40%;
top:25%;
left:30%;
z-index:9999;
background-color:#fff;
}
.black_overlay{
display:none;
width:100%;
height:100%;
background-color:#ccc;
position:absolute;
top:0;
left:0;
z-index:1;
filter: Alpha(opacity=50);
-moz-opacity:.5;
opacity:0.5;
}
/style
/head
body
div id="light" class="6866-a525-8e8c-4002 white_content"
div class="a525-8e8c-4002-a033 white_top"a href="javascript:void(0)" onclick="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'" 关闭/a/div
iframe src="funs/up.php" width="100%" height="auto" scrolling="auto" frameborder="0" style="clear:both; padding-top:5px;"/iframe
/div
div id="fade" class="8e8c-4002-a033-22ca black_overlay"/div
div class="4002-a033-22ca-3cb5 right"
div class="a033-22ca-3cb5-4f2d right_body"
table class="22ca-3cb5-4f2d-211f tab"
tr
td align="center"人物照片:
/td
tddiv id="pics" span id="span0"名称:
input type="text" size="20" id="pic_name0" name="pic_name[]"
地址:
input type="text" size="30" id="pic_url0" name="pic_url[]"
[a href="javascript:" onclick="upload(0)"font color="#ff0000"上传更换图片/font/a]/span
input type="button" value="添加上传文件" onclick="add_upload()"
/div
input type="hidden" id="num" name="num" value="1"
/td
/tr
/table
/div
/div
/body
/html
然后在本目录创建一个funs的文件夹,人后在里面创建一个up.php文件,放在,内容如下:
/******************************************************************************
参数说明:
$max_file_size : 上传文件大小限制, 单位BYTE
使用说明:
1. 将PHP.INI文件里面的"extension=php_gd2.dll"一行前面的;号去掉,因为我们要用到GD库;
2. 将extension_dir =改为你的php_gd2.dll所在目录;
******************************************************************************/
//上传文件类型列表
$uptypes=array(
'image/jpg',
'image/jpeg',
'image/png',
'image/pjpeg',
'image/gif',
'image/bmp',
'image/x-png'
);
$max_file_size=2000000; //上传文件大小限制, 单位BYTE
$destination_folder="../uploadimg/"; //上传文件路径
?
html
head
title添加上传图片/title
style type="text/css"
!--
body
{
font-size: 12px;
margin:0px;
}
input, select, textarea { border:1px solid #CCC; font-size:12px; padding:2px; font-family:"宋体"; }
--
/style
/head
body
form enctype="multipart/form-data" method="post" name="upform"
input name="upfile" type="file" size="30"
input type="submit" value="上传"br
span style="font-size:13px; color:#F00;"
允许上传的文件类型为:jpg, jpeg, png, pjpeg, gif, bmp, x-png/span
/form
?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (!is_uploaded_file($_FILES["upfile"][tmp_name]))
//是否存在文件
{
echo "图片不存在!";
exit;
}
$file = $_FILES["upfile"];
if($max_file_size $file["size"])
//检查文件大小
{
echo "文件太大!";
exit;
}
if(!in_array($file["type"], $uptypes))
//检查文件类型
{
echo "文件类型不符!".$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)
{
echo "同名文件已经存在了";
exit;
}
if(!move_uploaded_file ($filename, $destination))
{
echo "移动文件出错";
exit;
}
$pinfo=pathinfo($destination);
$fname=$pinfo[basename];
?
script type ="text/javascript"
?php
if(isset($_GET['label'])){//如果是批量上传?
window.parent.document.getElementById("pic_name?php echo $_GET['label']?").value = "?php echo $file["name"]?";
window.parent.document.getElementById("pic_url?php echo $_GET['label']?").value = 'uploadimg/?php echo $fname?';
window.parent.document.getElementById('light').style.display='none';
window.parent.document.getElementById('fade').style.display='none';
window.close();
?php }
else{?
window.parent.document.thisform.uploadfile.value='uploadimg/?=$fname?';
window.parent.document.getElementById("success").innerHTML=("上传成功! 宽度:?=$image_size[0]?px 长度:?=$image_size[1]?px 大小:?=$file["size"].' '.bytes?");
?php }?
/script
?
}
?
/body
PHP上传图片函数源码(重金悬赏)
?
//$_FILES['myFile']['tmp_name'] 储存的临时文件名,一般是系统默认
//is_uploaded_file()判断上传是否有内容
if(is_uploaded_file($_FILES['banner']['tmp_name'])){
//$_FILES["banner"]把上传的内容存到一个数组中,并复制给$upfile
$upfile = $_FILES["banner"];
//可以通过print_r($upfile);查看数据的详细内容
$name = $upfile["name"];
$type = $upfile["type"];
$size = $upfile["size"];
$tmp_name = $upfile["tmp_name"];
$error = $upfile["error"];
//switch循环用来为变量$ok赋值,如果图片的格式$type(实际上就是文件的扩展名)满足格式要求(循环里的case就是用来控制格式),那么$ok = 1,以便下边程序进行判断
switch($type){
case 'image/pjpeg': $ok = 1 ;
break;
case 'image/jpeg': $ok = 1 ;
break;
case 'image/gif': $ok = 1 ;
break;
case 'image/png': $ok = 1 ;
break;
}
if($ok$error=='0'){
//move_uploaded_file(临时文件,目标位置和文件名)
move_uploaded_file($tmp_name,'../up/'.$name);
echo "恭喜!上传成功";
}
if(!$ok){
echo "抱歉!文件格式不正确";
}
}
?
form action="" method="post" name="upform" enctype="multipart/form-data"
上传文件:
input type="file" name="banner" size="60" class="3cb5-4f2d-211f-b0eb t_input" /
input type="submit" name="submit" value="上传"/
/form
/*FORM标签enctype属性
表单中enctype="multipart/form-data"的意思,是设置表单的MIME编码。默认情况,这个编码格式是application/x-www-form-urlencoded,不能用于文件上传;只有使用了multipart/form-data,才能完整的传递文件数据
*/
php上传图片代码
等下,只是上传?那么简单,不用写到数据库么?
给个反映啊,不然我怎么帮你写。.....
好啦号啦,我写了:
title图片上传/title
/head
body
form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"
图片上传:
label
input type="file" name="file" id="file" /
/label
label
input type="submit" name="button" id="button" value="上传" /
/label
/form
?php
if(isset($_POST['button']))//检测按下了上传按钮
{
$file=$_FILES['file']['tmp_name'];//$_FILES是二维数组,file是文件;名,tmp_name是固定的,是上传到系统的位置
$name=date("Ymdgid").'.jpg';//上传以后,文件的新名字,用时间来做名字
$copy=copy($file,"photo/$name");//copy函数,是把文件拷贝到站点下的photo文件夹中
if($copy)//如果拷贝成功
echo '上传成功';
else
echo '上传失败';
}
?
/body
/html
菜鸟一只,求PHP批量上传图片的整个代码。
这是我写的图片批量上传的类:你直接调用就行了:
?php
function upload($fileName,$filePath)
{
//判断该文件是否是用户根据POST方式提交到服务器的上传文件
foreach($_FILES[$fileName]['tmp_name'] as $k=$v)
{
if($_FILES[$fileName]['name'][$k]!="")
{
$result=check($_FILES[$fileName]['size'][$k],$_FILES[$fileName]['type'][$k],$_FILES[$fileName]['name'][$k]);
if($result['error']==1)
{
echo $result['msg']."br";
echo "出错文件:".$result['name']."br";
}
else
{
$arrTT=explode(".",$_FILES[$fileName]['name'][$k]);
$extName=$arrTT[count($arrTT)-1];
$NewName=sha1(microtime()).".".$extName;
if(move_uploaded_file($v,$filePath.$NewName));
$arrWW[]=$NewName;
}
}
}
return $arrWW;
}
function check($size,$types,$name)
{
if($size=5242880)
{
$result['msg']='文件过大!';
$result['error']=1;
$result['name']=$name;
}
$arrType=array('image/pjpeg','image/gif','image/x-png','audio/mp3','application/msword','application/vnd.ms_excel','application/octet-stream','application/vnd.ms-powerpoint');
if(!in_array($types,$arrType))
{
$result['msg']='文件类型不匹配!';
$result['error']=1;
$result['name']=$name;
}
return $result;
}
?
其实,有很多php的图片上传的类,你可以去下载几个,看看怎么调用就行了
有没有PHP上传多张图片的源码学习一下
php文件上传与多文件上传其它没有多大的区别,多文件上传只是我们把表单名改成数组形式,而获取利用foreach遍历就可以实现多文件上传了,动态多文件上传只要在js加一个动态增加多文件上传框,同样在php处理时就遍
html
head
meta charset="utf-8"
titleindex_uploads/title
/head
body
form action="uploads.php" method="post" enctype="multipart/form-data"
input type="file" name="file[]"
br
input type="file" name="file[]"
br
input type="submit" value="uploads"
/form
/body
/html
uploads.php
?php
header("content-type:text/html;charset=utf-8");
echo "pre";
print_r($_FILES);
echo "/pre";
$count = count($_FILES['file']['name']);
for ($i = 0; $i $count; $i++) {
$tmpfile = $_FILES['file']['tmp_name'][$i];
$filefix = array_pop(explode(".", $_FILES['file']['name'][$i]));
$dstfile = "uploads/files/".time()."_".mt_rand().".".$filefix;
if (move_uploaded_file($tmpfile, $dstfile)) {
echo "scriptalert('succeed!');window.location.href='index_uploads.php';/script";
} else {
echo "scriptalert('fail!');window.location.href='index_uploads.php';/script";
}
}
核心:1上传首页中input的name属性是这么设置的。
2用while循环上传多文件。
php上传图片到服务器的前端和php代码
前端 代码 使用 extjs 3.4
uploadPhotoWindow=Ext.extend(Ext.Window,{
title:" 上传图片 Upload Photo",
height:420 ,
width:600,
closeAction:'close',
modal : true,
iconCls:'btn-setting',
buttonAlign: 'center',
upload_ok:false,
haveUpload:false,
initComponent : function() {
Ext.form.Field.prototype.msgTarget = 'side';
var po_no=new Ext.form.TextField({name:'Po_no',fieldLabel: '单号 Po No',itemId:'Po_no', width:120,
allowBlank: false, value:this.cur_sele_po_no, hidden:true});
var OP=new Ext.form.TextField({name:'OP',itemId:'OP', width:12,
allowBlank: false, value:"uploadphoto", hidden:true});
var file_name=new Ext.form.TextField({name:'photo_file_name',itemId:'photo_file_name', width:180,
allowBlank: false, value:"",hidden:true,});
var imagebox = new Ext.BoxComponent({
itemId:'imagebox',
autoEl: {
tag: 'img', //指定为img标签
style: 'height:100%;margin:0px auto;border:1px solid #ccc; text-align:center;margin-bottom:10px',
src: 'img/userimg/nophoto.jpg' , //指定url路径
}
});
var form_set_field = new Ext.FormPanel({
frame:true,
itemId:'form_set_field',
layout:'form',
//tableAttrs: {border: 1},
defaults:{labelAlign:'right',labelWidth:110,bodyStyle: 'padding:0 30px 0 0;',frame:false,layout:'form'},
items:[po_no,OP,file_name,imagebox],
});
var file = new Ext.form.TextField({
name: 'imgFile',
fieldLabel: '文件上传',
inputType: 'file',
allowBlank: false,
blankText: '请浏览图片'
});
var form_set_file = new Ext.FormPanel({
frame:true,
fileUpload: true,
itemId:'form_set_file',
layout:'form',
//tableAttrs: {border: 1},
defaults:{labelAlign:'right',labelWidth:110,bodyStyle: 'padding:0 30px 0 0;',frame:false,layout:'form'},
items:[file],
});
var btnOK= new Ext.Button({text: '上传 Upload ', iconCls:'btn-save',width:70,handler: function(){
var form_set=this.ownerCt.ownerCt.getComponent('form_set_file');
var form_set_field=this.ownerCt.ownerCt.getComponent('form_set_field');
var po_no=form_set_field.getComponent('Po_no').getValue();
var file_name=form_set_field.getComponent('photo_file_name');
//alert(po_no);
var imgbox=form_set_field.getComponent('imagebox');
if (form_set.getForm().isValid()){
form_set.getForm().submit({
waitMsg : '正在上传数据 Uploading....',waitTitle:'请稍候 waiting....',
url:'php/toolsfile/photoUpload.php',
method : 'post',
success : function(form, action){
var out = action.result.success;
if (out != true){
Ext.Msg.alert('提示 Tips ', '上传数据失败,错误信息 Save failure :'+action.result.msg);
//alert(action.result.msg);
} else{
//Ext.Msg.alert('提示 Tips ', '上传数据成功,服务器信息: Save success '+action.result.msg);
file_name.setValue(action.result.file_name);
imgbox.getEl().dom.src=action.result.file_scr;
form_set.ownerCt.savePhoto();
//form_set.ownerCt.grid.store.load();
//form_set.ownerCt.dateChang=true;
//form_set.ownerCt.destroy( );
}
},
failure: function(form, action) {
switch (action.failureType) {
case Ext.form.Action.CLIENT_INVALID:
Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
break;
case Ext.form.Action.CONNECT_FAILURE:
Ext.Msg.alert('Failure', 'Ajax communication failed');
break;
case Ext.form.Action.SERVER_INVALID:
Ext.Msg.alert('Failure', action.result.msg);
break;
}
},
});
}else{
Ext.Msg.alert('提示 Tips :', '请选择文件! \n Please select Img file ');
}
}
});
var btnCancel = new Ext.Button({text: ' 关闭 Close ', iconCls:'btn-cancel',width:70,handler: function(){this.ownerCt.ownerCt.destroy( )}});
Ext.apply(this,{
items: [form_set_field,form_set_file],
buttons: [btnOK, btnCancel],
});
uploadPhotoWindow.superclass.initComponent.call(this);
},
savePhoto:function (){
//alert(this.cur_sele_po_no);
var form_set_field=this.getComponent('form_set_field');
var form_set_file=this.getComponent('form_set_file');
form_set_field.getForm().submit({
waitMsg : '上传成功图片上传审核PHP源码,正在存储 saveing....',waitTitle:'请稍候 waiting....',
url:'php/jsonfile/po_nophotolist_json.php',
method : 'post',
success : function(form, action){
var out = action.result.success;
if (out != true){
Ext.Msg.alert('提示 Tips ', '存储失败,错误信息 Save failure :'+action.result.msg);
} else{
Ext.Msg.alert('提示 Tips ', '存储成功,服务器信息: Save success '+action.result.msg);
form_set_file.getForm().reset();
form_set_file.ownerCt.haveUpload=true;
}
},
failure: function(form, action) {
switch (action.failureType) {
case Ext.form.Action.CLIENT_INVALID:
Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
break;
case Ext.form.Action.CONNECT_FAILURE:
Ext.Msg.alert('Failure', 'Ajax communication failed');
break;
case Ext.form.Action.SERVER_INVALID:
Ext.Msg.alert('Failure', action.result.msg);
break;
}
},
});
},
isUpload:function(){
return this.haveUpload;
}
});
后台php photoUpload.php'
?
require_once('../classfile/guid.class.php');
if(!isset($_FILES['imgFile'])){
echo json_encode(array("success"=false, 'msg'="Not get Imgfile"));
return;
}
$upfile=$_FILES['imgFile'];
$name=$upfile["name"];//上传文件图片上传审核PHP源码的文件名
$type=$upfile["type"];//上传文件图片上传审核PHP源码的类型
$size=$upfile["size"];//上传文件的大小
$tmp_name=$upfile["tmp_name"];//上传文件的临时存放路径
$error_cod=$upfile["error"];
if ($error_cod0){
echo json_encode(array("success"=false, 'msg'=$error_cod));
}
$ext_file_name="";
switch ($type){
case 'image/pjpeg':
$okType=true;
$ext_file_name =".jpg";
break;
case 'image/jpeg':
$okType=true;
$ext_file_name =".jpg";
break;
case 'image/gif':
$okType=true;
$ext_file_name =".gif";
break;
case 'image/png':
$okType=true;
$ext_file_name =".png";
break;
}
if(!$okType){
echo json_encode(array("success"=false, 'msg'="Not image "));
return;
}
$web_root="D:".DIRECTORY_SEPARATOR."Easy2PHP5".DIRECTORY_SEPARATOR."webSiteJfz".DIRECTORY_SEPARATOR;
$photo_tmp_path=$web_root."img".DIRECTORY_SEPARATOR."userimg".DIRECTORY_SEPARATOR."temp";
$temp_file_name= creat_guid(0).$ext_file_name;
$photo_tmp_file_name=$photo_tmp_path.DIRECTORY_SEPARATOR.$temp_file_name;
$photo_tmp_file_scr="img".DIRECTORY_SEPARATOR."userimg".DIRECTORY_SEPARATOR."temp".DIRECTORY_SEPARATOR.$temp_file_name;
move_uploaded_file($tmp_name,$photo_tmp_file_name);
echo json_encode(array("success"=true, 'msg'= "ok","file_name"=$photo_tmp_file_name,"file_scr"=$photo_tmp_file_scr));
//echo json_encode(array("success"=false, 'msg'= json_encode($_FILES['imgFile'])));
return;
?
guid.class.php // 生成唯一的图片文件名
?
function creat_guid($long){
$uuid="";
if (function_exists('com_create_guid')){
$uuid=com_create_guid();
}else{
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = chr(123)// "{"
.substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12)
.chr(125);// "}"
//return $uuid;
}
if (!isset($long) || $long==0 ){
return substr($uuid,1, strlen($uuid)-2);
}else{
return $uuid;
}
}