File uploading in PHP

FILES super global variable File uploading in PHP Storing reference of uploaded file in database User registration in CONNECTIONS web application with file upload

pptx29 trang | Chia sẻ: dntpro1256 | Lượt xem: 562 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu File uploading in PHP, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
File uploading in PHPBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.1Summary of the previous lectureCreating database in MySQL using WAMPConnecting PHP with MySQLInserting data in databaseCONNECTIONS: user registration Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.2OutlineFILES super global variableFile uploading in PHPStoring reference of uploaded file in databaseUser registration in CONNECTIONS web application with file uploadBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.31. $_FILES: super-global variable$_FILES: contains any item uploaded to the server when the post method is usedan array type variableCreated automatically Can be accessed on other pagesBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.41. $_FILES: super-global variableKeeps information aboutNameSizeType Tmp_nameBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.51. $_FILES: super-global variableFORM attributes required:Method should be postEnctype should be multipart/form-dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.61. $_FILES: super-global variableBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.7File typenameAsadChoose FilesubmitNo File ChosenMypci.jpgnameAsad$_POST$_FILESpic[name]=>file name[type]=>file type[size]=>file size=>tmp name[tmp_name]1. $_FILES: super-global variableBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.8Accessing file information$_FILES[‘input-field name’][‘name’];$_FILES[‘pic’][‘name’];$_FILES[‘input-field name’][‘type’];$_FILES[‘pic’][‘type’];$_FILES[‘input-field name’][‘size’];$_FILES[‘pic’][‘size’];1. $_FILES: super-global variableBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.9enctypemethodInput fieldSubmit button1. $_FILES: super-global variableBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.10Display files arrayFile nameFile typeFile sizetmp name1. $_FILES: super-global variableBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.11Selected fileFiles arrayFile nameFile typeFile sizeTemp name2. Uploading filemove_uploaded_file():bool move_uploaded_file ( string $filename , string $destination );This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism) If the file is valid, it will be moved to the filename given by destinationBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.122. Uploading fileBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.13basename():returns the filename from a path Example:retutns index.php2. Uploading fileBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.14File upload steps:Identify the file to be uploadedtmp_name is usedDefine destinationLocation + file nameUpload the file2. Uploading fileBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.15File tmp nameFile nameFolder + filenameFile uploaded2. Uploading fileBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.16Restricting Users:Size restrictionType restrictionFile rename2. Uploading fileBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.17Retrieving file attributesFile renameSize and typeFile uploaded3. Storing reference to databaseBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.18nameemailpasswordpictureMethod is postEnctype=“multipart/form-data”3. Storing reference to databaseBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.193. Storing reference to databaseBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.20DB connectionExecuting queryInsert queryredirection3. Storing reference to databaseBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.213. Storing reference to databaseBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.22Record is added3. Storing reference to databaseBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.234. CONNECTIONS: registration actionBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.24nameemailpasswordpostpic4. CONNECTIONS: registration actionBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.25Input is retrievedFile is uploadedDB connection4. CONNECTIONS: registration actionBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.26Input is validated4. CONNECTIONS: registration actionBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.27Data is inserted‘$password’,SummaryFILES super global variableFile uploading in PHPStoring reference of uploaded file in databaseUser registration in CONNECTIONS web application with file uploadBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.28References Chapter 30, “Beginning PHP and MySQL” by W. Jason Gilmore, Apress publisher, 4th edition; 2010, ISBN-13 (electronic): 978-1-4302-3115-8.Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.29

Các file đính kèm theo tài liệu này:

  • pptxlec29_file_uploading_in_php_8729_2026977.pptx