GVKun编程网logo

织梦上传bmp图片出现Upload filetype not allow!解决办法(织梦上传图片大小设置)

7

如果您对织梦上传bmp图片出现Uploadfiletypenotallow!解决办法和织梦上传图片大小设置感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解织梦上传bmp图片出现Uploadfil

如果您对织梦上传bmp图片出现Upload filetype not allow!解决办法织梦上传图片大小设置感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解织梦上传bmp图片出现Upload filetype not allow!解决办法的各种细节,并对织梦上传图片大小设置进行深入的分析,此外还有关于AjaxFileUpload(1)Simple File Upload Sample、ajaxFileUpload+php图片上传预览、ajaxfileupload.js结合input[type=file]无刷新上传、Apache FileUpload的两种上传方式介绍及应用 --> upload file done! --> upload file done!的实用技巧。

本文目录一览:

织梦上传bmp图片出现Upload filetype not allow!解决办法(织梦上传图片大小设置)

织梦上传bmp图片出现Upload filetype not allow!解决办法(织梦上传图片大小设置)

 

相信不少同学看了《织梦后台不支持上传bmp格式图片的解决办法》教程后,上传bmp格式图片的时候,还是遇到Upload filetype not allow !图片上传出错的情况!

  解决办法如下:

  *步:找到根目录“include”这个文件夹,点击进去

  第二步:找到“include”这个文件下的“uploadsafe.inc.php”文件,点击打开

  第三步:在打开“uploadsafe.inc.php”文件的大概第45行:找到$imtypes = array,并将其改为$imgtypes = array

织梦上传bmp图片出现Upload filetype not allow!解决办法

  *后一步:把更改好的uploadsafe.inc.php文件上传到“include”这个文件下就可以解决了!

本文章网址:http://www.ppssdd.com/code/10851.html。转载请保留出处,谢谢合作!

AjaxFileUpload(1)Simple File Upload Sample

AjaxFileUpload(1)Simple File Upload Sample

总结

以上是小编为你收集整理的AjaxFileUpload(1)Simple File Upload Sample全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

ajaxFileUpload+php图片上传预览

ajaxFileUpload+php图片上传预览

后台是利用SWFUpload上传图片,是flash+js的组合,如果不用chrome,经常会提示flash版本过低用不了,感觉还是很不方便的。

这里总结了一利用js ajax上传的插件列表: 7 JAVASCRIPT AJAX FILE UPLOAD PLUGINS

jQuery插件之ajaxFileUpload 原理都是创建隐藏的表单和iframe然后用JS去提交,获得返回值。

前台做的时候有一个坑,之前是用的$('element').change()来获取事件,但是onchange事件只会被触发一次,网上有提到解决的办法是live('change'),可惜项目jquery太旧并不支持,也不敢随意升级。所以只能直接在input中加入onchange=“function()”来实现。

这里有关于onchange事件的详细讲解:input的onchange事件实际触发条件与解决方法

一、当input捕获到焦点后,系统储存当前值

二、当input焦点离开后,判断当前值与之前存储的值是否不等,如果为true则触发onchange事件。

##前台代码 浏览器自己的file input比较丑,所以一般都display:none然后下面加一个

function uploadRear() {
		$.ajaxFileUpload({
			url:'{url:/ucenter/ajax_addr_identity_upload}',secureuri:false,fileElementId: 'strPhotoRear1',dataType: 'json',success: function (data) {
				if(data.error == '200'){
					$("#img-r").attr('src','{url:/' + data.data + '}');
					$('input[name="card_id_reverse"]').val(data.data);
					$('#strPhotoRear1').val();
				} else {
					art.dialog({
						content: data.data
					});
				}
			}
		});
	}

##php后台代码 利用了一个IUpload的类,foreach $_FILES,检查扩展名和图片木马,然后再上传。 先要了解PHP预定义变量$_FILES的格式:

Array
(
    [file1] => Array
        (
            [name] => MyFile.txt (comes from the browser,so treat as tainted)
            [type] => text/plain  (not sure where it gets this from)
            [tmp_name] => /tmp/php/php1h4j1o
            [error] => UPLOAD_ERR_OK  (= 0)
            [size] => 123   (the size in bytes)
        )

    [file2] => Array
        (
            [name] => MyFile.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/php/php6hst32
            [error] => UPLOAD_ERR_OK
            [size] => 98174
        )
)

这是在input name为file1和file2的情况,如果是写为file[img1],file[img2],则处理为了以下模式(官方文档推荐了diverse_array()的trick):

Array
(
    [file] => Array
        (
            [name] => Array
                (
                    [img1] => MyFile.txt
                    [img2] => MyFile.jpg
                )
        ...

controller中的代码,返回处理后的消息给前台:

public function ajax_addr_identity_upload(){
        $file_dir = 'upload/addr_identity/';
        $uploader = new IUpload('5120'); //5M
        $sub_dir = date('Y') . '/' . date('m') . '/'. date('d');
        $uploader->setDir(trim($file_dir,'/') . '/' . $sub_dir);
        $res = $uploader->execute();
        //判断文件上传并生成数据
        if ((isset($res['picfront']) && $res['picfront'][0]['flag'] == 1) || (isset($res['picback']) && $res['picback'][0]['flag'] == 1)) {
            $return['error'] = '200';
            $return['data'] = empty($res['picfront'][0]['fileSrc']) ? $res['picback'][0]['fileSrc'] : $res['picfront'][0]['fileSrc'];
            $size = filesize($result['data']) / 1024;
            $code = new Config('code_config');
            $max_size = $code->card_id_max_size;
            if($size > $max_size){
                $proportion = number_format(($max_size/$size)*100);
                $this->createThumb($return['data'],$proportion);
            }
        }
        else
        {
            $return['error'] = '301';
            $return['data'] = '上传失败';
        }
        echo json_encode($return);exit();
    }

IUpload类中比较关键的方法

public function setDir($path,$chmod=0777){
    $dir = is_dir($path) or (self::mkdir(dirname($path),$chmod) and mkdir($path,$chmod));
    $dir = strtr($dir,'\\','/');
    $this->dir = substr($dir,-1)=='/' ? $dir : $dir.'/';
}
public function execute(){
    //总的文件上传信息
    $info = array();
    foreach($_FILES as $fid => $file) {
            $fileInfo = array();
             //不存在上传的文件名
            if(!isset($_FILES[$fid]['name']) || $_FILES[$fid]['name'] == '')
            {
            	continue;
            }
            //上传控件为数组格式 file[]格式
            if(is_array($_FILES[$fid]['name'])){
                 $keys = array_keys($_FILES[$fid]['name']);
                 foreach($keys as $key) {
                    //调用成员检查上传类型,pathinfo()获取
                    $fileInfoArray = pathinfo($_FILES[$fid]['name'][$key]);
                     #code 检查上传大小 $_FILES[$field]['size'][$key] 
                     #code 图片木马检测
                     #开始上传 is_uploaded_file/mkdir/move_upload_file(tmp_name,dir+name)
                 }
           } else{
                //非文件数组上传方式
                #$fileInfo[0]['name'] = $_FILES[$field]['name'];
           }
            $info[$fid] = $fileInfo;   
    }

ajaxfileupload.js结合input[type=file]无刷新上传

ajaxfileupload.js结合input[type=file]无刷新上传

jQuery插件AjaxFileUpload用来实现ajax文件上传,该插件使用非常简单,接下来写个demo演示怎么用AjaxFileUpload插件实现文件上传。

说明:

语法:$.ajaxFileUpload([options])

  options参数说明:

1、url           上传处理程序地址。  
2,fileElementId      需要上传的文件域的ID,即<input type="file">的ID。
3,secureuri        是否启用安全提交,默认为false。
4,dataType        服务器返回的数据类型。可以为xml,script,json,html。如果不填写,jQuery会自动判断。
5,success        提交成功后自动执行的处理函数,参数data就是服务器返回的数据。
6,error          提交失败自动执行的处理函数。
7,data          自定义参数。这个东西比较有用,当有数据是与上传的图片相关的时候,这个东西就要用到了。
8,type           当要提交自定义参数时,这个参数要设置成post

错误提示:

1,SyntaxError: missing ; before statement错误
  如果出现这个错误就需要检查url路径是否可以访问
2,SyntaxError: Syntax error错误
  如果出现这个错误就需要检查处理提交操作的服务器后台处理程序是否存在语法错误
3,SyntaxError: invalid property id错误
  如果出现这个错误就需要检查文本域属性ID是否存在
4,SyntaxError: missing } in XML expression错误
  如果出现这个错误就需要检查文件name是否一致或不存在
5,其它自定义错误
  大家可使用变量$error直接打印的方法检查各参数是否正确,比起上面这些无效的错误提示还是方便很多。


1、引入其支持文件,注意引用顺序

<script type="text/javascript" src="<%=basePath%>js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/ajaxfileupload.js"></script>

2、在页面设置文件选择框,无需form包裹:注意此处id和name必须设置,在文章中你将知道原因,在此不做详细解释。

<input type="file" id="fileUpload" name="fileUploa" />

3、实现上传功能

<script type="text/javascript">
    //初始化页面
	$(document).ready(function(e) {
		 //选择文件框选择文件change事件
		 $("#fileUpload").change(function(){
			 var url=$(this).val();
			 var extend=url.substring(url.indexOf(".")+1);
			 var ext=new Array("jpg","jpeg","png","gif","bmp");
			 if(ext.toString().indexOf(extend)==-1){
				 alert("您上传的格式不正确,仅支持jpg、jpeg、png、gif、bmp,请重新选择!");
			 }
			 
			 $.ajaxFileUpload({
			        url: '<%=basePath%>attach/api/upload',//后台提交地址
			        secureuri: false,//异步
			        fileElementId: 'fileUpload',//上传控件ID
			        dataType: 'json',//返回的数据信息格式
			        type:"post",//如果带附加参数,请设置type
			        success: function(data,status) {
			            if (data.success ==true) {
			               var attach=data.result[0];
			               $("[name=photo]").attr("src",attach.filePath);
			               alert("上传成功");
			             } else {
			                alert("服务器故障,稍后再试!");
			            }
			        },error: function(data,status,e) {
			           alert(e);
			        }
			    });
			});

	});
</script>
4、后台接口:此处采用spring MVC

@RequestMapping(value = "/upload",method ={RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public HashMap<String,Object> upload(HttpServletRequest request,HttpServletResponse response)
                                                    throws InstantiationException,illegalaccessexception{
		HashMap<String,Object> result=new HashMap<String,Object>();
		ArrayList<Attach> attachList=attachService.uploadfy(request);
		if(attachList.size()>0){
			result.put("success",true);		
			result.put("result",attachList);
		}else{
			result.put("success",false);		
		}
	    return result;
	}
5、实现以上步奏即可完成上传。

总结:

在使用过程中可能遇到如下问题:

1、上传报该异常:SyntaxError:Unexpected token <

原因:是因为Server端的Response上加上了contentType="application/json"。但有时后端这么做是必须的,所以修改ajaxFileUpload源码,将<pre></pre>标签去掉,如下: (请参考:http://liwx2000.iteye.com/blog/1540321)

uploadHttpData: function( r,type ) {  
        var data = !type;  
        data = type == "xml" || data ? r.responseXML : r.responseText;  
        // If the type is "script",eval it in global context  
        if ( type == "script" )  
            jQuery.globalEval( data );  
        // Get the JavaScript object,if JSON is used.  
        if ( type == "json" ) {  
             ////////////以下为新增代码///////////////  
             data = r.responseText;  
             var start = data.indexOf(">");  
             if(start != -1) {  
               var end = data.indexOf("<",start + 1);  
               if(end != -1) {  
                 data = data.substring(start + 1,end);  
                }  
             }  
              ///////////以上为新增代码///////////////  
              eval( "data = " + data);  
        }  
        // evaluate scripts within html  
        if ( type == "html" )  
            jQuery("<div>").html(data).evalScripts();  
  
        return data;  
    }  
2、使用<input type="file" id="fileUpload" />该方式,在后台接收不到值? 原因:需要设置一下name属性 <input type="file" id="fileUpload" name="名称任意" />

Apache FileUpload的两种上传方式介绍及应用 --> upload file done! --> upload file done!

Apache FileUpload的两种上传方式介绍及应用 --> upload file done! --> upload file done!

本文为大家介绍下FileUpload的两种上传方式:Traditional API上传方式/Streaming API上传方式,感兴趣的朋友可以参考下哈,希望可以帮助到你

环境

tomcat5.6

commmons-fileupload-1.3.jar

commmons-io-2.4.jar

JSP

编码:UTF-8

临时文件夹:fileupload/tmp相对于网站根目录

上传文件保存位置:fileupload

Traditional API上传方式

//fileload01.htm

复制代码 代码如下:

File to upload:

to upload the file!

//Traditionalapi.jsp

复制代码 代码如下:

request.setCharacterEncoding("UTF-8");

// file less than 10kb will be store in memory, otherwise in file system.

final int threshold = 10240;

final File tmpDir = new File(getServletContext().getRealPath("/") + "fileupload" + File.separator + "tmp");

final int maxRequestSize = 1024 * 1024 * 4; // 4MB

// Check that we have a file upload request

if(ServletFileUpload.isMultipartContent(request))

{

// Create a factory for disk-based file items.

FileItemFactory factory = new diskFileItemFactory(threshold, tmpDir);

// Create a new file upload handler

ServletFileUpload upload = new ServletFileUpload(factory);

// Set overall request size constraint.

upload.setSizeMax(maxRequestSize);

List items = upload.parseRequest(request); // FileUploadException

for(FileItem item : items)

{

if(item.isFormField()) //regular form field

{

String name = item.getFieldName();

String value = item.getString();

%>

-->

}

else

{ //file upload

String fieldName = item.getFieldName();

String fileName = item.getName();

File uploadedFile = new File(getServletContext().getRealPath("/") +

"fileupload" + File.separator + fieldName + "_" + fileName);

item.write(uploadedFile);

%>

upload file done!

}

}

}

%>

Streaming API上传方式

//fileupload02.htm

复制代码 代码如下:

File to upload:

to upload the file!

//streamingapi.jsp

复制代码 代码如下:

request.setCharacterEncoding("UTF-8");

// Check that we have a file upload request

if(ServletFileUpload.isMultipartContent(request))

{

// Create a new file upload handler

ServletFileUpload upload = new ServletFileUpload();

// Parse the request

FileItemIterator iter = upload.getItemIterator(request);

while(iter.hasNext())

{

FileItemStream item = iter.next();

String fieldName = item.getFieldName();

InputStream is = item.openStream();

if(item.isFormField()) //regular form field

{

%>

-->

}

else

{ //file upload

String fileName = item.getName();

File uploadedFile = new File(getServletContext().getRealPath("/") +

"fileupload" + File.separator + fieldName + "_" + fileName);

OutputStream os = new FileOutputStream(uploadedFile);

// write file to disk and close outputstream.

Streams.copy(is, os, true);

%>

upload file done!

}

}

}

%>

Traditional API vs Streaming API

Streaming API上传速度相对较快。因为它是利用内存保存上传的文件,节省了传统API将文件写入临时文件带来的开销。

可参考:

http://stackoverflow.com/questions/11620432/apache-commons-fileupload-streaming-api

This page describes the Traditional API of the commons fileupload library. The Traditional API is a convenient approach. However, for ultimate performance, you might prefer the faster Streaming API.

http://commons.apache.org/proper/commons-fileupload/using.html

我们今天的关于织梦上传bmp图片出现Upload filetype not allow!解决办法织梦上传图片大小设置的分享就到这里,谢谢您的阅读,如果想了解更多关于AjaxFileUpload(1)Simple File Upload Sample、ajaxFileUpload+php图片上传预览、ajaxfileupload.js结合input[type=file]无刷新上传、Apache FileUpload的两种上传方式介绍及应用 --> upload file done! --> upload file done!的相关信息,可以在本站进行搜索。

本文标签: