function Ajaxfileupload () {$.ajaxfileupload ({url: ' upfile.php ', Secureuri:false, Fileelementid: ' pic ', DataType: ' JSON ', success:function (data, status) { if (typeof (Data.error)! = ' undefined ') { if (data.error! = ') { alert (data.error); } else{ alert (data.msg);}} , error:function (data, status, E) { alert (e);}} ) return false;}
+ Add a picture
upfile.php
$upFilePath = ". /useruploaddatas/". $_session ["UserId"]. "/"; $res ["error"] = ""; Error message $res ["msg"] = "exec"; Hint Information if (copy ($_files [' pic '] [' tmp_name '], $upFilePath. $_files [' pic '] [' name ']) {$res ["msg"] = "OK";} else {$re s ["error"] = "error";} echo Json_encode ($res);
Unable to upload the file, do not know where there is a problem ... I hope the warrior pointed
Reply to discussion (solution)
Who's the Boss?
Make sure your JS section doesn't have a big difference from the sample file.
Check to make sure the file is not uploaded.
Exit (Json_encode ($_files));
JS script is not error Ah, you are under the Firebug console to see there is no error.
I just tested it under FF.
Without any hint of error, it made me very embarrassed.
Get not to file, what's going on.
Full code:
Upload file Form upfileform.php
Website Column Management
Upload file server side upfile.php
!--? phpheader ("content-type:text/html; Charset=utf-8 "); $upFilePath =". /useruploaddatas/". $_session ["UserId"]. " /"; $res [" error "] =" "; Error message $res ["msg"] = ""; Hint Information if (@move_uploaded_file (@$_files ["Filetoupload"] ["Tmp_name"], $upFilePath. @$_files ["Filetoupload"] ["name"] ) {$res ["msg"] = "OK";} else {$res ["error"] = "error";} echo Json_encode ($res);
can't live Ajax upload Ah, direct
files can be uploaded, I am not clear, how I write the above code to AJAX upload files, depressed a few days,, do not know why.
first remove
Look, there may be a conflict
boss, has removed the jrosion.js, the same effect. 。
you write only in upfile.php
!--? Phpecho ' {"msg": "Hello "}'; Try
Note that there must be no BOM header
I can't stand, downloaded a wrong ajaxfileupload.js file, and finally downloaded one in csdn, no problem, I'm depressed not, as if in Download the website ....