<!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=gbk"/>
<title>ajax file upload download by http://www.111cn.net</title><link href="css/style.css" rel="stylesheet" type="text/css"/>
<script type="text/网页特效" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="js/jquery.livequery.min.js"></script>
<script type="text/javascript" src="js/jquery.ajaxmultifileupload.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#maincol").ajaxmultifileupload();
});
</script>
</head><body>
<div id="maincol"></div>
</body>
</html>//php代码
<?php
function _resize($_w, $max_w, $_h, $max_h) {
global $new_w, $new_h;
if ($_w>$max_w || $_h>$max_h) {
$x_ratio = $max_w / $_w;
$y_ratio = $max_h / $_h;
if (($x_ratio * $_h) < $max_h) {
$new_h = ceil($x_ratio * $_h);
$new_w =$max_w;
}
else {
$new_w = ceil($y_ratio * $_w);
$new_h=$max_h;
}
}
else {
$new_w = $_w;
$new_h=$_h;
}
}if ($_files) {
foreach ($_files as $f) {
// get actual image type
$ext = strtolower(str_replace("image/", "", image_type_to_mime_type(exif_imagetype($f['tmp_name']))));
// get image type from file extension
$ext_file = strtolower(str_replace("image/", "", $f['type']));
// adjustment for ie mime types
$ext_adjust = array("pjpeg" => "jpeg", "x-png" => "png");
$ext_file = (array_key_exists($ext_file, $ext_adjust)) ? $ext_adjust[$ext_file] : $ext_file;
// check if file actual and ext file types match
if ( ($ext_file != $ext) ) {
$ps教程t = array("problem" => array("name" =>$f['name'], "ext" => $ext, "ext_actual" => $ext_file));
}
else {
$stat = stat($f['tmp_name']);
$renamed = ($_post['mode']=='demo') ? $stat[9].'.'. substr(strrchr($f['name'], "."),1) : $f['name'];
// set path for upload directory
$f['_upload'] = $_server['document_root'] . $_post['upload'] . $renamed;
// set path for image thumbnail directory
$f['_thumb'] = $_server['document_root'] . $_post['thumb'] . $renamed;
$f['src'] = "thumb/" . $renamed;
chmod($f['tmp_name'], 0755);
// get image size - requires gd library
list($width, $height) = getimagesize($f['tmp_name']);
$max_width = 120;
$max_height = 60;
_resize($width, $max_width, $height, $max_height);// create thumbnail with image_class (files included in download)
include_once('imageclass/image_class.inc');
set_time_limit(140);
try{
// create new image from posted $_files
$image=& new image($f['tmp_name']);
$image->resize(round($new_w),round($new_h));
// save image to thumbnail directory
$image->saveimage($f['_thumb'],$image->getimagedata());
$image->clean();
// move actual posted $_files to upload directory
$moved = move_uploaded_file($f['tmp_name'], $f['_upload']);
if ($moved) $pst = array ("img" => array("alt" => $f['_thumb'], "src" => $f['src'], "name" => $f['name'], "rename" => $renamed, "width" => $new_w, "height" => $new_h));
}
catch(exception $e){
$pst = array ("problem" => array("name" =>$f['name'], "error" => $e->__tostring()) );
}
}
echo "var pst = " . json_encode($pst);
}
}
else if ($_post['deletefile']) {
$_file = ($_post['mode']=='demo') ? urldecode($_post['deletefile']) : urldecode($_post['origname']);
// delete tmp file
$_unlink_upload = unlink($_server['document_root'] . $_post['upload'] . $_file);
// delete thumb file
$_unlink_thumb = unlink($_server['document_root'] . $_post['thumb']. $_file);
if ($_unlink_thumb && $_unlink_upload) echo "file <span>" . $_post['origname'] . "</span> deleted.";
else echo "problem deleting file " . $_file . ".";
}
/*
文件下载地址
http://down.111cn.net/php/2010/0901/20569.html
*/