当提交表双时,捕捉提交历程并测验考试运转下列代码片断来上传文件 -
// File 1 var myFile = document.getElementById('fileBox').files[0]; var reader = new FileReader(); reader.readAsText(file, 'UTF-8'); reader.onload = myFunc; function myFunc(event) { var res = event.target.result; var fileName = document.getElementById('fileBox').files[0].name; $.post('/myscript.php', { data: res, name: fileName }, continueSubmission); }
登录后复造
而后,正在办事器端(即 myscript.php) -
$data = $_POST['data']; $fileName = $_POST['name']; $myServerFile = time().$fileName; // Prevent overwriting $fp = fopen('/uploads/'.$myServerFile,'w'); fwrite($fp, $data); fclose($fp); $retData = array( "myServerFile" => $myServerFile ); echo json_encode($retData);
登录后复造
以上即是应用HTML5文件上传取AJAX以及jQuery的具体形式,更多请存眷萤水红IT仄台其余相闭文章!
发表评论 取消回复