+ -
当前位置:首页 → 问答吧 → 成批图片上传程序

成批图片上传程序

时间:2008-01-15

来源:互联网

复制内容到剪贴板
代码:
<LINK href="../images/main.css" type=text/css rel=stylesheet>
<?
require "../../conn.php";
?>
<script type="text/javascript">
<!--
var onecount;
subcat = new Array();
        <?
        $count = 0;
        $strsql="select smallclassname,bigclassname from smallclass order by id asc";
  $result=mysql_query($strsql,$myconn);
       while($row = mysql_fetch_array($result))
  {
        ?>
subcat[<? echo $count; ?>] = new Array("<? echo $row["smallclassname"];?>","<? echo $row["bigclassname"]; ?>","<? echo $row["smallclassname"];?>");
        <?
        $count = $count + 1;
        }
  ?>
onecount=<? echo $count; ?>;
function changelocation(locationid)
    {
    document.myform.SmallClassName.length = 1;
    var locationid=locationid;
    var i;
    for (i=0;i < onecount; i++)
        {
            if (subcat[1] == locationid)
            {
                document.myform.SmallClassName.options[document.myform.SmallClassName.length] = new Option(subcat[0], subcat[2]);
            }        
        }
    }   



function setid(){
var abc="fsfsf";
document.getElementById("Submit").disabled=false;
oAjA=document.getElementById("upcount")
str='';
if(!oAjA.value){oAjA.value=2;}
if(oAjA.value==0){oAjA.value=2;}
if(oAjA.value==1){oAjA.value=2;}
if(oAjA.value>20){
  alert("您最多只能同时处理 20个图片!");
  oAjA.value = 20;
  setid();
}else{
  for(i=1;i<=oAjA.value*2;i++)
  if(i % 2 == 0){
   k=(i/2)
   if( k<10){a="0"}else{a="";}
   str+=' 远程原始图地址'+a +k+ ':<input type="file" name="upfile'+k+'" id="upfile'+k+'" class=a1  size="40" contentEditable=false ><br>';
     }else{
      if(abc!="0"){
    str+='缩略图:系统自动生成||';
   }else{
    str+='远程缩略图地址:<input type="file" name="upfile'+k+'" id="upfile'+k+'" class=a1 size="40" >';
   }
         }
  document.getElementById("upid").innerHTML=str+'';
}
}

function check(){
form=document.myform;
if(form.bookname.value=="")
{
  alert("请填写用户名!");
  form.bookname.focus();
  return false;
}

  if(form.BigClassName.value=="")
{
  alert("请选择大类!");
  form.BigClassName.focus();
  return false;
}

   if(form.SmallClassName.value =="")
{
  alert("请选择小类!");
  form.SmallClassName.focus();
  return false;
}



}


//-->   
</script>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
<tr class="topbg">
  <td height="22" align="center"><strong>成批获取</strong> </td>
</tr>
</table>
<table align="center" border="0" width="100%" cellspacing="1" cellpadding="0" class="border">
  <form  name="myform" method="post" action="addphook.php" enctype="multipart/form-data"  >
  <tr class="title">
   <td height="22" class="title" colspan="2"><strong>|
   <a href="adminfile.asp">管理图片</a> | <a href="addbook.asp">单图上传</a> |
   <a href="addall.asp">成批上传</a> | <a href="allurl.asp">成批加入</a> |
   <a href="addget.asp">成批获取</a> | <a href="addfso.asp">文件夹导入</a> |
   </strong></td>
  </tr>
    <tr class="tdbg">
      <td width="120" align="right" class="x">选择分类: </td>
      <td align="left">
   <select name="BigClassName"  size="1">
   
        <option selected="selected" value="">请选择大类</option>
        <?     $str="select bigclassname from bigclass order by id asc";
     $result2=mysql_query($str,$myconn);
     while($rw = mysql_fetch_array($result2))
     { ?>
        <option value="<? echo $rw["bigclassname"];?>"><? echo $rw["bigclassname"];?></option>
        <? }?>
      </select>
   
        <select name="SmallClassName">
          <option value="" selected="selected">不指定小类</option>
         </select></td>
    </tr>
    <tr class="tdbg">
      <td width="120" align="right">图片名称:</td>
      <td>
<input name="bookname" type="text" id="bookname" size="25" class="a1"> *
      <input type="text" name="upcount" id="upcount" value="2" size=5 class='a1' >
      <input type="button" name="Button" id="Button"   value="设定上传图片数">
      </td>
    </tr>
    <tr class="tdbg">
      <td id="upid" colspan="2"> </td>
    </tr>
    <tr class="tdbg">
      <td height="30" colspan="2" align="center">
        <input type="submit" name="Submit" id="Submit" disabled value="添 加" >
      </td>
    </tr>
    <tr class="tdbg">
      <td width="120" valign="top" align="right">注意:</td>
      <td>必须填写带有“*”项目<br>
  填写图片名称时,系统自动在后面加上数字<br>
</td>
    </tr>
    </form>
  </table>
[ 本帖最后由 forest 于 2008-1-15 17:50 编辑 ]

作者: wdpchange   发布时间: 2008-01-15

复制PHP内容到剪贴板
PHP代码:

<?php
header("content-Type: text/html; charset=gb2312");
$uptypes=array('image/jpg',  //上传文件类型列表
'image/jpeg',
'image/png',
'image/pjpeg',
'image/gif',
'image/bmp',
'application/x-shockwave-flash',
'image/x-png',
'application/msword',
'audio/x-ms-wma',
'audio/mp3',
'application/vnd.rn-realmedia',
'application/x-zip-compressed',
'application/octet-stream');
$max_file_size=20000000;   //上传文件大小限制, 单位BYTE
$path_parts=pathinfo($_SERVER['PHP_SELF']); //取得当前路径
$destination_folder="up/"; //上传文件路径
$watermark=1;   //是否附加水印(1为加水印,其他为不加水印);
$watertype=1;   //水印类型(1为文字,2为图片)
$waterposition=1;   //水印位置(1为左下角,2为右下角,3为左上角,4为右上角,5为居中);
$waterstring="[url=http://www.332020.cn/]www.332020.cn[/url]"; //水印字符串
$waterimg="xplore.gif";  //水印图片
$imgpreview=1;   //是否生成预览图(1为生成,其他为不生成);
$imgpreviewsize=1/2;  //缩略图比例
?>

复制PHP内容到剪贴板
PHP代码:

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
include "lib/activeCodeObj.php";
$code = new activeCodeObj;
$zu=$code->getCode(6,1);
$str =$zu."_".$code->getCode(20,0);
$counts = $_POST['upcount'];
$phoc="";
for ($i=1;$i<=$counts;$i++)
{
if (!is_uploaded_file($_FILES["upfile".$i][tmp_name]))
//是否存在文件
{
echo "<font color='red'>文件不存在!</font>";
exit;
}
$file = $_FILES["upfile".$i];
if($max_file_size < $file["size"])
//检查文件大小
{
echo "<font color='red'>文件太大!</font>";
exit;
  }
if(!in_array($file["type"], $uptypes))
//检查文件类型
{
echo "<font color='red'>不能上传此类型文件!</font>";
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.$str._.$i.".".$ftype;
$picc=$str._.$i.".".$ftype;
$phoc=$phoc.$picc."#";
if (file_exists($destination) && $overwrite != true)
{
     echo "<font color='red'>同名文件已经存在了!</a>";
     exit;
  }
if(!move_uploaded_file ($filename, $destination))
{
   echo "<font color='red'>移动文件出错!</a>";
     exit;
  }
$pinfo=pathinfo($destination);
$fname=$pinfo[basename];
//echo " 宽度:".$image_size[0];
//echo " 长度:".$image_size[1];
if($watermark==1)
{
$iinfo=getimagesize($destination,$iinfo);
$nimage=imagecreatetruecolor($image_size[0],$image_size[1]);
$white=imagecolorallocate($nimage,255,255,255);
$black=imagecolorallocate($nimage,0,0,0);
$red=imagecolorallocate($nimage,255,0,0);
imagefill($nimage,0,0,$white);
switch ($iinfo[2])
{
case 1:
$simage =imagecreatefromgif($destination);
break;
case 2:
$simage =imagecreatefromjpeg($destination);
break;
case 3:
$simage =imagecreatefrompng($destination);
break;
case 6:
$simage =imagecreatefromwbmp($destination);
break;
default:
die("<font color='red'>不能上传此类型文件!</a>");
exit;
}
imagecopy($nimage,$simage,0,0,0,0,$image_size[0],$image_size[1]);
imagefilledrectangle($nimage,1,$image_size[1]-15,80,$image_size[1],$white);
switch($watertype)
{
case 1:  //加水印字符串
imagestring($nimage,2,3,$image_size[1]-15,$waterstring,$black);
break;
case 2:  //加水印图片
$simage1 =imagecreatefromgif("xplore.gif");
imagecopy($nimage,$simage1,0,0,0,0,85,15);
imagedestroy($simage1);
break;
}
switch ($iinfo[2])
{
case 1:
//imagegif($nimage, $destination);
imagejpeg($nimage, $destination);
break;
case 2:
imagejpeg($nimage, $destination);
break;
case 3:
imagepng($nimage, $destination);
break;
case 6:
imagewbmp($nimage, $destination);
//imagejpeg($nimage, $destination);
break;
}
//覆盖原上传文件
imagedestroy($nimage);
imagedestroy($simage);
}
}
}
$title=$_POST["bookname"];
$time=date("Y-m-d");
$uip=$HTTP_SERVER_VARS["REMOTE_ADDR"];
require "../../conn.php";
$Qsmallclass=$_POST["SmallClassName"];
$Qbigclass = $_POST["BigClassName"];
if ( empty($Qsmallclass) == false )
{

  $sqloo="insert into userpho(userid,title,bigclass,smallclass,zu,pho,ip,addtime) values('wdpchange','$title','$Qbigclass','$Qsmallclass','$zu','$phoc','$uip','$time')";
  $result2=mysql_query($sqloo,$myconn)or die(mysql_error());
  echo "<script language='javascript'>alert('成功保存!');window.document.location.href='addpho.php';</script>";
   
}

?>

[ 本帖最后由 forest 于 2008-1-15 17:52 编辑 ]

作者: wdpchange   发布时间: 2008-01-15

高深

作者: 五五互联   发布时间: 2008-01-15

楼主数据表的结构也要发上来,还有如果写成函数或类,给出调用的方法就更好了,代码帮你高亮显示了!
不过总体来说写的还不错,鼓励一下!

作者: forest   发布时间: 2008-01-15

看得太累了,应该辅以文档说明啊。

作者: luzhou   发布时间: 2008-01-15

好乱....

作者: liuxingyuyuni   发布时间: 2008-01-16

热门下载

更多