1. [代码][PHP]代码
//首先 准备 swfupload 包
//前端用户体验页面
html>
<title>SWFUpload Demos - Application Demo</title><link><script></script><script></script><script></script><script>
$(function(){
$('#btn').bind('click',path);
});
function path()
{
var url='';
$('#thumbnails img').each(function(){
url=$(this).attr('id')+'{#@T@#}'+url;
})
alert(url);
}
var swfu;
window.onload = function () {
swfu = new SWFUpload({
// Backend Settings
upload_url: "upload.php",
post_params: {"PHPSESSID": "<?php echo session_id(); ?>"},
// File Upload Settings
file_size_limit : "800", // 2MB 最大容量限制
file_types : "*.jpg",
file_types_description : "JPG Images",
file_upload_limit : 5,//上传数量限制
// Event Handler Settings - these functions as defined in Handlers.js
// The handlers are not part of SWFUpload but are part of my website and control how
// my website reacts to the SWFUpload events.
swfupload_preload_handler : preLoad,
swfupload_load_failed_handler : loadFailed,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
// Button Settings
button_image_url : "images/SmallSpyGlassWithTransperancy_17x18.png",
button_placeholder_id : "spanButtonPlaceholder",
button_width: 200,
button_height: 18,
button_text : '<span class="button">Select Images <span class="buttonSmall">(800 k Max)[*.jpeg]',
button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }',
button_text_top_padding: 0,
button_text_left_padding: 18,
button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
button_cursor: SWFUpload.CURSOR.HAND,
// Flash Settings
flash_url : "./swfupload/swfupload.swf",
flash9_url : "./swfupload/swfupload_FP9.swf",
custom_settings : {
upload_target : "pFileProgressContainer"
},
// Debug Settings
debug: false
});
};
</script><h2>最多上传5张图片<h2>
</h2>
</h2>
//后台处理页面 upload.php
$img_ratio) {
$new_height = $target_height;
$new_width = $img_ratio * $target_height;
} else {
$new_height = $target_width / $img_ratio;
$new_width = $target_width;
}
if ($new_height > $target_height) {
$new_height = $target_height;
}
if ($new_width > $target_width) {
$new_height = $target_width;
}
$new_img = ImageCreateTrueColor(100, 100);
if (!@imagefilledrectangle($new_img, 0, 0, $target_width-1, $target_height-1, 0)) { // Fill the image black
echo "ERROR:Could not fill new image";
exit(0);
}
if (!@imagecopyresampled($new_img, $img, ($target_width-$new_width)/2, ($target_height-$new_height)/2, 0, 0, $new_width, $new_height, $width, $height)) {
echo "ERROR:Could not resize image";
exit(0);
}
if (!isset($_SESSION["file_info"])) {
$_SESSION["file_info"] = array();
}
// Use a output buffering to load the image into a variable
ob_start();
imagejpeg($new_img);
$imagevariable = ob_get_contents();
ob_end_clean();
$file_id = md5($_FILES["Filedata"]["tmp_name"] + rand()*100000);
$_SESSION["file_info"][$file_id] = $imagevariable;
//上传图片处理
if(!is_dir("uploadimage"))
{
mkdir("uploadimage");
}
$pre_fix=md5('120ask120');
move_uploaded_file($_FILES["Filedata"]["tmp_name"],trim("./uploadimage/".$pre_fix.$file_id.".jpg"));
/*图片处理结束*/
echo "FILEID:" . $file_id; // Return the file id to the script
?>