PHP+Jquery AjaxUploadʵÏÖÎļþÉÏ´«¹¦ÄÜ´úÂëʵÀý½Ì³Ì
2011-05-04 20:10:39 | 1´ÎÔĶÁ | ÆÀÂÛ£º0 Ìõ | itokit
¡¡¡¡ÔÚPHPÍøÕ¾¿ª·¢ÖУ¬ÎļþÉÏ´«¹¦ÄÜʱ³£Óõ½£¬Ö®Ç°ÎÒÒѽéÉܹýÈçºÎÀûÓÃPHPʵÏÖÎļþÉÏ´«¹¦ÄÜ¡£Ëæ×ÅWEB¼¼ÊõµÄ·¢Õ¹£¬Óû§ÌåÑé³ÉΪºâÁ¿ÍøÕ¾³É¹¦Óë·ñµÄ¹Ø¼ü£¬½ñÌìºÍ´ó¼Ò·ÖÏíÈçºÎÔÚPHPÖÐÀûÓÃJqueryʵÏÖAjax·½Ê½ÎļþÉÏ´«¹¦ÄܵÄÀý×Ó£¬ÆäÖÐʹÓõ½ÁËJquery²å¼þAjaxupload£¬Æä¿ÉÒÔʵÏÖµ¥¸öÎļþºÍ¶àÎļþÉÏ´«¹¦ÄÜ¡£
AjaxUpload
¡¡¡¡Jquery²å¼þAjaxUploadʵÏÖÎļþÉÏ´«¹¦ÄÜʱÎÞÐè´´½¨form±íµ¥£¬¼´¿ÉʵÏÖAjax·½Ê½µÄÎļþÉÏ´«£¬µ±È»¸ù¾ÝÐèÒªÒ²¿ÉÒÔ´´½¨form±íµ¥¡£
×¼±¸¹¤×÷
1¡¢ÏÂÔØJquery¿ª·¢°üºÍÎļþÉÏ´«²å¼þAjaxUpload¡£
2¡¢´´½¨uploadfile.html£¬²¢ÒýÈëJquery¿ª·¢°üºÍAjaxUpload²å¼þ
XML/HTML Code¸´ÖÆÄÚÈݵ½¼ôÌù°å
3¡¢¸ù¾ÝJquery²å¼þAjaxUploadµÄÐèÒª£¬´´½¨Ò»¸ö´¥·¢AjaxÎļþÉÏ´«¹¦ÄܵÄDIV
PHP Code¸´ÖÆÄÚÈݵ½¼ôÌù°å
×¢ÊÍ£ºÓÉÏÂÃæµÄ´úÂëÎÒÃÇ¿ÉÒÔ¿´µ½Jquery²å¼þAjaxUploadÊǸù¾Ýupload_buttonÕâ¸öDIV´¥·¢ÎļþÉÏ´«¹¦ÄÜ¡£
ǰ̨JS´úÂë
¡¡¡¡ÔÚ´úÂëÖÐÎÒÉèÖÃÁË¿ª¹Ø£¬¸ù¾ÝÐèÒª¿ÉÒÔÆ¥ÅäÉÏ´«ÎļþÀàÐÍ£¬Í¬Ê±Ò²¿ÉÒÔÉèÖÃÊÇÒÔAjax·½Ê½ÊµÏÖµ¥¸öÎļþÉÏ´«»¹ÊǶà¸öÎļþÉÏ´«¡£
PHP Code¸´ÖÆÄÚÈݵ½¼ôÌù°å
×¢ÊÍ£º
µÚ1ÐУº$(document).ready()º¯Êý£¬JqueryÖеĺ¯Êý£¬ÀàËÆÓÚwindow.load£¬Ê¹ÓÃÕâ¸öº¯Êý¿ÉÔÚDOMÔØÈë¾ÍÐ÷Äܹ»¶ÁÈ¡²¢²Ù×ÝʱÁ¢¼´µ÷Óð󶨵ĺ¯Êý¡£
µÚ3ÐУºfileTypeºÍfileNum²ÎÊý´ú±íÉÏ´«ÎļþµÄÀàÐͺÍÊýÁ¿£¬Ä¬ÈÏֵΪ¿ÉÉÏ´«ËùÓÐÀàÐÍÎļþ£¬Í¬Ò»Ê±¼äÖ»ÄÜÉÏ´«Ò»¸öÎļþ£¬ÈçÏëÉÏ´«Í¼Æ¬Îļþ»òͬʱÉÏ´«¶à¸öÎļþ£¬¿É½«ÕâÁ½¸ö±äÁ¿Öµ±äΪpicºÍmore¡£
µÚ6~8ÐУºPOSTµ½·þÎñÆ÷µÄÊý¾Ý£¬Äã¿ÉÒÔÉèÖþ²Ì¬ÖµÒ²¿ÉÒÔͨ¹ýJqueryµÄDOM²Ù×÷º¯Êý»ñµÃһЩ¶¯Ì¬Öµ£¬±ÈÈçform±íµ¥ÖÐINPUTµÄÖµµÈ¡£
µÚ9ÐУºµÈͬÓÚÇ°¶Ë
PHP Code¸´ÖÆÄÚÈݵ½¼ôÌù°å
·þÎñÆ÷¶Ë$_FILES['userfile']
µÚ10~36ÐУºÎļþÉÏ´«Ç°´¥·¢µÄ¹¦ÄÜ¡£
µÚ11~21ÐУºÍ¼Æ¬ÎļþÀàÐ͵ĹýÂ˹¦ÄÜ£¬Jquery setDataº¯ÊýÓÃÀ´ÉèÖÃPOSTÖÁ·þÎñÆ÷¶ËµÄÖµ¡£
µÚ25~26ÐУºÉèÖÃͬʱֻÉÏ´«Ò»¸öÎļþ»¹ÊǶà¸öÎļþ£¬Èç¹ûÖ»ÉÏ´«Ò»¸öÎļþ£¬Ôò½«´¥·¢°´Å¥½ûµô¡£Èç¹ûÒª¶à´«Ê伸¸öÎļþ£¬ÇëÔÚ·þÎñÆ÷¶ËPHPÎļþÉÏ´«³ÌÐòÖÐÉèÖÃMAXSIZEµÄÖµ£¬µ±È»ÉÏ´«ÎļþµÄ´óСÏÞÖÆͬʱºÍPHP.INIÎļþÖеÄÉèÖÃÒ²Óйء£
µÚ28~35ÐУºÔÚÎļþÉÏ´«¹ý³ÌÖÐÿ¸ô200ºÁÃ붯̬¸üÐÂÒ»´Î°´Å¥µÄÎÄ×Ö£¬ÒÑʵÏÖ¶¯Ì¬ÌáʾµÄЧ¹û¡£window.setIntervalº¯ÊýÓÃÀ´Ã¿¸ôÖ¸¶¨µÄʱ¼ä¾ÍÖ´ÐÐÒ»´ÎÄÚÖõĺ¯Êý£¬½»»¥Ê±¼äµ¥Î»ÎªºÀÃë¡£
µÚ37~49ÐУºÎļþÉÏ´«¹¦ÄÜÍê³Éºó´¥·¢µÄ¹¦ÄÜ£¬¸ù¾Ý·µ»ØÖµÈç¹û·þÎñÆ÷¶Ë±¨´í£¬ÔòÇ°¶Ëͨ¹ýALERT·½Ê½Ìáʾ³ö´íÐÅÏ¢¡£
·þÎñÆ÷¶ËPHPÎļþÉÏ´«´úÂë
¡¡¡¡´óÌåÉÏÊǸù¾Ý֮ǰ½éÉܵÄPHPÎļþÉÏ´«¹¦ÄÜ´úÂëʵÀý½Ì³Ì¸Ä±à£¬Éæ¼°µ½µÄÎļþÉÏ´«´óСµÄÉèÖ㬳ö´íÐÅÏ¢µÈ˵Ã÷¶¼ÒÑÔÚ´ËÎÄÖÐÏêϸ˵Ã÷¡£
PHP Code¸´ÖÆÄÚÈݵ½¼ôÌù°å
×ܽá
¡¡¡¡»ù±¾ÉÏÇ°¶ËAjaxÎļþÉÏ´«´¥·¢¹¦ÄܺͷþÎñÆ÷¶ËPHPÎļþÉÏ´«¹¦ÄܵÄÔÐ;ͽéÉÜÍê±ÏÁË£¬Äã¿ÉÒÔ¸ù¾Ý×ÔÉíÐèÒª¶ÔÇ°ºó¶Ë´úÂë½øÐв¹³ä£¬Ò²¿ÉÒÔ½«Ò»Ð©¹¦ÄܶÀÁ¢³öÀ´£¬±ÈÈçÎļþÀàÐÍ¡¢µ¥¸öÎļþ»òÕ߶àÎļþÉÏ´«¹¦ÄÜ¡£×ܵÄÀ´ËµJquery²å¼þAjaxUploadʵÏÖÎļþÉÏ´«¹¦ÄܵÄÓ¦Óû¹ÊDZȽÏÈÝÒ׵ġ£
±¾ÎĹؼü´Ê£º
ÉÏһƪ: Æƽâphp-screw¼ÓÃܹýµÄÎļþÓÐЧ·½·¨ ÏÂһƪ: PHPÀûÓÃignore_user_abortʵÏÖÈÎÎñ¼Æ»®µÄʵÀý½Ì³Ì
ÆÀÂÛ¼ÓÔØÖÐ...Ïà¹ØÎÄÕÂ
¡¡