php文件上传程序(支持缩略图)(1/2)

 代码如下 复制代码

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>上传文件程序</title>
<style type="text/css教程">
*{
 font-size:12px;
 margin:0; padding:0;
}
a:link,a:visited{
 text-decoration:none;
 color: #393
}
a:hover{
 text-decoration:underline;
 color:#0033cc
}
input.text{
 border:1px solid #ccc;height:22px;line-height:22px;padding-left:5px;background:#fff;width:274px;
}
input.button{
 background:#fff url(images/button.png);border:1px solid #9ea9c5;padding:2px 2px 0px 2px;margin-left:4px; margin-right:4px;
}
</style>
<script language=网页特效>
function check()
{
 var strfilename=document.myform.upfile.value;
 if (strfilename=="")
 {
     alert("请选择要上传的文件");
  document.myform.upfile.focus();
     return false;
   }
}
</script>
</head>

<body>
<?php
/***********************
程序:上传文件
功能:上传文件、缩略图、加水印
****************************/
include("common/upfiles.class.php");
$path="../upload/coolsite";    //文件上传路径
$mix="smallimg";     //缩略图路径(在upload下建立)
$mark="markimg";    //加水引的图片存放路径(在upload下建立)
$text = array("www.111cn.net");   //水印内容
$oupload= new upfiles($path,$mix,$mark);   //实例化类文件

if(isset($_post['up'])){
 
 if($_post['urlid']=='1'){ //上传图片 参数urlid 1:上传图片  2:上传其他文件..
  
  $oupload->tofile = true;  //开启则只保存缩略图或者水印图,删除原图
  $photo = $oupload->upload("upfile"); //上传的文件域
  $photourl = $oupload->fileurl."/".$photo;
  $newsmallimg = $oupload->smallimg($photo);  //缩略图功能
  //$newmarkimg = $oupload->watermark($photo,$text); //水印功能

  //echo $newsmallimg;  //输出缩略图路径
  //echo $newmark; //输出水印图路径
  //echo "<img src='".$newsmallimg."' border='0'>"; //输出缩略图
  //echo "<img src='".$newmark."' border='0'>"; //输出水印图
 }else{
  $upfilename = $oupload->upload("upfile"); //上传的文件域
 }
 $strjs = "<script language=javascript> ";
 $strjs .= "parent.document.myform.upfile1.value='".$newsmallimg."' ";
 $strjs .= "parent.document.myform.upfile2.value='".$photourl."' ";
 $strjs .= "</script> ";
 echo $strjs;  //把上次文件路径附在upfile1、upfile2中去
}else{
?>
<form action="upfile.php" method="post" enctype="multipart/form-data" name="myform" onsubmit="return check()">
<input type="file" name="upfile" value="" class="text"><input type="submit" name="up" value="上传" class="button">
<input type="hidden" name="urlid" value="<?php echo $_get['urlid']?>">
</form>
<?php }?>
</body>
</html>

<?
//upfiles.class.php

/*=========================
上传类 upfiles.class.php
===========================*/
class upfiles {
  /*=========================
   //基本参数设置
  ===========================*/
        protected $annexfolder = "upload";  //附件存放点,默认为:upload
  protected $dirtype = 2;   //1:按天存入目录 2:按月存入目录
        protected $smallfolder = "smallimg";   //缩略图存放路径,注:必须是放在 $upload下的子目录,默认为:smallimg
        protected $markfolder = "markimg";    //水印图片存放路径,注:必须是放在 $upload下的子目录,默认为:markimg
        protected $upfiletype = "jpg gif png rar zip";   //上传的类型,默认为:jpg gif png rar zip
        protected $upfilemax = 102400;   //上传大小限制,单位是"kb",默认为:1024kb
        protected $fonttype = "common/equinoxstd.otf";   //水印字体库
        protected $maxwidth = 800;   //图片最大宽度
        protected $maxheight = 600;  //图片最大高度
  
  /*=========================
   //初始化上传类
  ===========================*/
        public function __construct($annexfolder,$smallfolder,$includefolder) {
   
    switch($this->dirtype)
    {
     case 1: $attach_subdir = 'day_'.date('ymd'); break;
     case 2: $attach_subdir = 'month_'.date('ym'); break;
    }
    $attach_dir = $annexfolder.'/'.$attach_subdir;
    $attach_dir_small = $attach_dir.'/'.$smallfolder;
    $attach_dir_mark = $attach_dir.'/'.$includefolder;    
    
    $this->rootfolder = $annexfolder;
                $this->annexfolder = $attach_dir;
                $this->smallfolder = $attach_dir_small;
    $this->markfolder = $attach_dir_mark;
                //$this->fonttype = $includefolder."/nasaliza.ttf";
        }
  public function __get($fileurl){
   $fileurl = $this->annexfolder;
   return $fileurl;
  }
  /*=========================
   //上传文件
  ===========================*/
        public function upload($inputname) {
    //检查文件夹是否存在    
    if(!file_exists($this->annexfolder)){
     if(!file_exists($this->rootfolder)) @mkdir($this->rootfolder);
     if(!file_exists($this->annexfolder)) @mkdir($this->annexfolder);
     if(!file_exists($this->smallfolder)) @mkdir($this->smallfolder);
     if(!file_exists($this->markfolder)) @mkdir($this->markfolder);
    }
    if(!file_exists($this->smallfolder)){
     @mkdir($this->smallfolder);
    }    
    if(!file_exists($this->markfolder)){
     @mkdir($this->markfolder);
    }
        
    $this->uptype = $_files[$inputname]["type"];
    $this->upname = $_files[$inputname]["name"];
    $this->uptmp_name = $_files[$inputname]["tmp_name"];
    $this->ups教程ize = $_files[$inputname]["size"];
    $this->uperror = $_files[$inputname]["error"];

    if($this->uptype){
     switch ($this->uptype)///检查上传的类型
     {    
      case "image/pjpeg":    
       $fileextname = "jpg";    
       break;
      case "image/jpeg":    
       $fileextname = "jpg";    
       break;  
      case "image/gif":    
       $fileextname = "gif";    
       break;    
      case "image/x-png":    
       $fileextname = "png";    
       break;    
      case "application/x-shockwave-flash":    
       $fileextname = "swf";    
       break;    
      case "text/plain":    
       $fileextname = "txt";    
       break;    
      case "application/msword":    
       $fileextname = "doc";    
       break;
      case "application/vnd.ms-excel":    
       $fileextname = "xls";    
       break;
      case "application/x-zip-compressed":    
       $fileextname = "zip";    
       break;
      case "audio/mpeg":
       $fileextname = "mp3";    
       break;
      case "audio/x-ms-wma":
       $fileextname = "wma";    
       break;
      case "application/pdf":
       $fileextname = "pdf";    
       break;
      default: //如果不满足上述类型,那么上传文件被判断为格式不正确!!
       //$fileextname  =strtolower(substr(strrchr(trim($this->upname), "."),1,4));
       //$fileinfo=pathinfo($this->upname);
       //$fileextname=$fileinfo['extension'];
       $fileextname = "err";
      }
     }
    

 

首页 1 2 末页

时间: 2024-08-28 04:46:56

php文件上传程序(支持缩略图)(1/2)的相关文章

jsoup 文件上传不支持怎么办?

问题描述 jsoup 文件上传不支持怎么办? jsoup 文件上传不支持怎么办?post一个文件上传的url connect 报500

超简单的php文件上传程序

 代码如下 复制代码 <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv=&qu

ASP.NET文件上传程序的源代码

asp.net|程序|上传|源代码 本文件用VB.NET编辑,在WIN2000+IIS(安装有.NET支持)中调试通过,可以上传许多常用的文件类型.如RAR.ZIP.DOC.TXT.JPG.GIF等等!直接下载保存为ASPX格式就可以------------------------------------------------------------<html><title>文件上传</title> <body><form enctype="

实现ASP.NET多文件上传程序代码_实用技巧

upload.aspx 复制代码 代码如下: <%@ Page language="c#" Codebehind="UpLoad.aspx.cs" AutoEventWireup="false" Inherits="WebPortal.Upload" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

简单的jsp文件上传程序

 代码如下 复制代码 <html> <title>上传</title> <style type="text/css">  body {font:12px Tahoma;font-family:"宋体";margin:0px;background:#f3f8fb;}  body,form,ul,li,p,dl,dd,dt,h,td,th,h3{padding:0;font-size:12px;color:#444;}  

php中实现图片文件上传程序代码

我们先来看一下项目结构图与数据库结构图吧 项目结构: 运行效果:   up.html 简单的上传表单文件  代码如下 复制代码 <form action="up.php" enctype="multipart/form-data" method="post"      name="uploadfile">上传文件:<input type="file" name="upfile&q

文件上传程序的全部源码

1.upfile.php文件 <html> <body> <title>文件上传</title> <form enctype="multipart/form-data" action=upload.php method=post> <input type=file name=upfile size=10><br><br> <input type=submit value='上载文件'&

文件上传程序的全部源码_php基础

1.upfile.php文件 <html> <body> <title>文件上传</title> <form enctype="multipart/form-data" action=upload.php method=post> <input type=file name=upfile size=10><br><br> <input type=submit value='上载文件'&

php无刷新文件上传程序代码

在一个网站项目中,为了得到更好的用户体验,很多地方都要处理成异步无刷新的效果.此文件上传范例是利用一个隐藏的框架iframe做桥梁,实现主体页面上传文件无刷新的效果. 其实本范例也不是真正的异步效果,但是也是可以达到无刷新效果的.而且这种方法是实现php无刷新上传文件最快捷,最简单的方法,所以何乐而不为呢. html代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.