English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
이 문서는 php+프로세스 바가 있는 이미지 업로드 기능을 ajax로 구현했습니다. 모두에게 공유하고 참고해 주세요. 구체적으로는 다음과 같습니다:
실행 이미지는 다음과 같습니다:
아래는 코드입니다:
<?php if(isset($_FILES["FileInput"]) && $_FILES["FileInput"]["error"]== UPLOAD_ERR_OK) { ############ 설정 편집 ############## $UploadDirectory = 'F:'/웹사이트/file_upload/uploads/'; //지정된 업로드 디렉토리가 끝나는 / (slash) ########################################## /* Note : You will run into errors or blank page if "memory_limit" or "upload_max_filesize" is set to low in "php.ini". Open "php.ini" file, and search for "memory_limit" or "upload_max_filesize" limit and set them adequately, also check "post_max_size". */ //check if this is an ajax request if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])){ die(); } //Is file size is less than allowed size. if ($_FILES["FileInput"]["size"] > 5242880) { die("File size is too big!"); } //allowed file type Server side check switch(strtolower($_FILES['FileInput']['type'])) { //allowed file types case 'image/png': case 'image/gif': case 'image/jpeg': case 'image/pjpeg': case 'text/plain': case 'text/html': //html file case 'application/x-zip-compressed': case 'application/pdf': case 'application/msword': case 'application/vnd.ms-excel': case 'video/mp4: break; default: die('Unsupported File!'); //output error } $File_Name = strtolower($_FILES['FileInput']['name']); $File_Ext = substr($File_Name, strrpos($File_Name, '.')); //get file extention $Random_Number = rand(0, 9999999999);}} //이름에 추가될 랜덤 번호. $NewFileName = $Random_Number.$File_Ext; //new file name die('성공! 파일 업로드됨.'); { else{ } die('파일 업로드 중 오류!'); } } else { die('업로드 중 문제가 발생했습니다! 'upload_max_filesize'가 올바르게 설정되었는지 확인했습니다吗?');63;'); }
전체 예제 코드를 클릭하여이 사이트 다운로드。
PHP와 관련된 더 많은 내용에 대해 관심이 있는 독자는 이 사이트의 특辑을 확인할 수 있습니다: 《PHP 파일 작업 요약》、《PHP 계산 및 연산자 사용 요약》、《PHP 네트워크 프로그래밍 기술 요약》、《PHP 기본 문법 입문 교본》、《PHP office 문서 작업 기술 요약(Word, Excel, Access, PPT 포함)》、《PHP 날짜 및 시간 사용 요약》、《PHP面向对象程序设计入门教程》、《PHP 문자열(string) 사용 요약》、《PHP+mysql 데이터베이스 작업 입문 교본》 및 《php 일반 데이터베이스 작업 기술 요약》
이 문서에서 설명된 내용이 여러분의 PHP 프로그램 설계에 도움이 되길 바랍니다.
선언: 이 문서의 내용은 인터넷에서 가져왔으며, 저작권은 원작자에게 있으며, 인터넷 사용자가 자발적으로 기여하고 업로드한 내용입니다. 이 사이트는 소유권을 가지지 않으며, 인공 편집을 하지 않았으며, 관련 법적 책임도 부담하지 않습니다. 저작권 침해가 의심되는 내용을 발견하시면, notice#w로 이메일을 보내 주세요.3codebox.com에 대한 신고를 위해 이메일을 보내시면, #을 @으로 변경하시고 관련 증거를 제공하시면 됩니다. 확인되면, 이 사이트는 즉시 저작권 침해 내용을 삭제합니다.