界面语言:简体中文 软件大小:未知
文件类型:.exe 发布时间:2009-09-14
此文档为swfuplaod上传例子. 可以上传单文件多文件.迅雷下载源码。已经测试无错误!
部分代码
- <?php
- // Work-around for setting up a session because Flash Player doesn't send the cookies
- /* if (isset($_POST["PHPSESSID"])) {
- session_id($_POST["PHPSESSID"]);
- }
- session_start();
- if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
- echo "There was a problem with the upload";
- exit(0);
- } else {
- echo "Flash requires that we output something or it won't fire the uploadSuccess event";
- }
- */
- $updir="./upload/";//上传目录
- $dirtype="1";//目录保存方式1:年/月/日;2:年/月;默认:年
- $renamed="1";//是否重命名1表示重命名0表示用原来的文件名
- $overwrite="1";//是否覆盖1表示覆盖0表示不覆盖
- if (isset($_FILES["Filedata"]) && is_uploaded_file($_FILES["Filedata"]["tmp_name"]) && $_FILES["Filedata"]["error"] == 0) {
- //上传文件赋值给$upload_file
- $upload_file=$_FILES["Filedata"];
- //获取文件类型
- $file_info=pathinfo($upload_file["name"]);
- //获取文件扩展名
- $file_ext=$file_info["extension"];
- //设置路径方式
- switch($dirtype){
- case '1':
- $m_dir=date(Y)."/".date(m)."/".date(d)."/";
- break;
- case '2':
- $m_dir=date(Y)."/".date(m)."/";
- break;
- default:
- $m_dir=date(Y)."/";
- break;
- }
- //设置上传的路径
- $upload_path=$updir.$m_dir;
- //建立文件夹
- create($upload_path);
- //需要重命名的
- if($renamed){
- list($usec, $sec) = explode(" ",microtime());
- $upload_file['name']=substr($usec,2).'.'.$file_ext;
- unset($usec);
- unset($sec);
- }
- //设置默认服务端文件名
- $upload_file['filename']=$upload_path.$upload_file['name'];
- //检查文件是否存在
- if(file_exists($upload_file['filename'])){
- if($overwrite){
- @unlink($upload_file['filename']);
- }else{
- $j=0;
- do{
- $j++;
- $temp_file=str_replace('.'.$file_ext,'('.$j.').'.$file_ext,$upload_file['filename']);
- }while (file_exists($temp_file));
- $upload_file['filename']=$temp_file;
- unset($temp_file);
- unset($j);
- }
- }
- if(@move_uploaded_file($upload_file["tmp_name"],$upload_file["filename"])){
- //下面插入一段把路径保存到数据库中的代码;
- // Create a pretend file id, this might have come from a database.
- //产生一个上传文件id,这可能来自数据库;
- //这里必需echo内容可以是文件id或许数据库中的id,不然程序会出现错误,没有内容传回到index.php表单中的hidFileID中
- echo $upload_file["filename"];
- }else{
- echo '';
- }
- } else {
- echo ' '; // I have to return something or SWFUpload won't fire uploadSuccess
- }
- //建立文件夹
- function create($dir)
- {
- if (!is_dir($dir))
- {
- $temp = explode('/',$dir);
- $cur_dir = '';
- for($i=0;$i<count($temp);$i++)
- {
- $cur_dir .= $temp[$i].'/';
- if (!is_dir($cur_dir))
- {
- @mkdir($cur_dir,0777);
- @fopen("$cur_dir/index.htm","a");
- }
- }
- }
- }
- ?>
完整案例在附件:请下载
温馨提示:
①:如果您发现有php批量上传支持图片和文件免费下载,而绿色php资源未能索引到,请及时通知我们。您的热心是对绿色php资源网最大的支持。
②:php批量上传支持图片和文件是优秀的免费的资源,索引php批量上传支持图片和文件链接到本站只是为了让您方便下载。支持作者请购买正版。
③:本网站是一个免费绿色php资源下载站,仅提供php批量上传支持图片和文件资源免费下载,若有下载php批量上传支持图片和文件资源者请24小时后自行删除。
④:如果作品浏览,或对php批量上传支持图片和文件作品内容、版权等方面有质疑,或对绿色php资源网有意见建议请及时反馈给我们,以便我们及时处理!