Khoá học lập trình PHP&MYSQL - Bài 48: Upload File PHP

Hienu Tech
4 Jun 202212:20

Summary

TLDRThe video script is a tutorial focused on uploading files using PHP. It guides viewers through creating a form and server-side processing to handle file uploads efficiently. The host discusses setting up a folder structure, handling file names, and navigating potential issues like slow processing. The script also covers checking for POST method data, server variables, and implementing file upload functionality using FTP. The tutorial aims to help viewers understand the backend process of file uploads in web development.

Takeaways

  • 😀 The video is a tutorial focused on teaching viewers how to upload files in PHP.
  • 🛠️ The presenter creates a new folder named 'upload' to store files and discusses the importance of file organization.
  • 📝 They mention creating a form for file uploads and discuss the need for a 'flash' element, possibly referring to Adobe Flash for file handling.
  • 🔧 The script discusses the creation of a 'phone' form for file uploads, indicating a step-by-step process.
  • 🌐 The presenter talks about handling file uploads with PHP, including checking for the 'post' method and file data.
  • 📂 They mention the use of a 'server' variable to access uploaded files and the importance of validating file types and sizes.
  • 📁 The video covers the process of moving uploaded files to a specified directory using PHP's 'move_uploaded_file' function.
  • 🖼️ The presenter demonstrates how to handle image uploads, including file type validation and error handling.
  • 📝 There's a mention of using FTP (File Transfer Protocol) to upload files, indicating a step for transferring files to a server.
  • 🔗 The script includes a discussion on URL rewriting for file uploads, ensuring that uploaded files are accessible via a web URL.

Q & A

  • What is the main topic discussed in the script?

    -The main topic discussed in the script is about uploading files in PHP and creating a new form for handling file uploads.

  • What is the purpose of creating a new folder named 'PhongLuan'?

    -The purpose of creating a new folder named 'PhongLuan' is to store information related to the file upload process.

  • What does the term 'loa' refer to in the context of the script?

    -In the context of the script, 'loa' refers to the flash component used in the file upload form.

  • Why is it necessary to check the file upload method in the script?

    -It is necessary to check the file upload method to ensure that the data is being transmitted correctly, either through a POST method or another method.

  • What is the role of the 'server' variable in the script?

    -The 'server' variable in the script contains all the information received from the file upload, including the file name and its path.

  • What is the significance of the '$_FILES' variable in the script?

    -The '$_FILES' variable is significant as it holds the uploaded file information, which is crucial for processing and storing the file.

  • Why is it important to check if the file upload method is POST in the script?

    -Checking if the file upload method is POST is important because it verifies that the file data is being sent correctly through the form for processing.

  • What does the script suggest to do if the file upload method is not POST?

    -If the file upload method is not POST, the script suggests not to process the file upload and to handle the situation accordingly.

  • What is the function of the 'move_uploaded_file' function mentioned in the script?

    -The 'move_uploaded_file' function is used to move the uploaded file from its temporary location to a specified directory.

  • How does the script handle file names with special characters or spaces?

    -The script handles file names with special characters or spaces by suggesting to sanitize or modify the file name to avoid issues during the file upload process.

Outlines

00:00

😀 Introduction to PHP File Uploading

The speaker begins by welcoming the audience back to their channel and introduces a tutorial on how to upload files in PHP. They mention creating a new project and setting up a server environment. The tutorial aims to guide viewers through the process of handling file uploads, including creating a folder to store files and setting up a form for file submission. The speaker also discusses the importance of checking the file upload method and ensuring the server can handle the incoming data.

05:01

😀 Detailed Explanation of File Upload Process

In this paragraph, the speaker delves deeper into the file upload process in PHP. They explain the need to check for the existence of a file and the method of data transmission, whether it's through POST or GET. The speaker also talks about handling file names and paths, ensuring that the server can process and store the uploaded files correctly. They mention using FTP to transfer files to a server and discuss the importance of naming files appropriately for easy identification and retrieval.

10:01

😀 Finalizing the File Upload Tutorial

The final paragraph wraps up the tutorial by summarizing the steps taken to upload files using PHP. The speaker demonstrates how to use FTP to transfer files to a server and how to rename them for clarity. They also show how to check the file's properties, such as size and type, before uploading. The speaker concludes by emphasizing the importance of understanding the file upload process for effective web development and server management.

Mindmap

Keywords

💡Upload

Upload refers to the process of transferring data or files from a local system to a remote server or another computer over a network. In the context of the video, the main theme revolves around teaching viewers how to upload files in PHP, which is a crucial skill for web development. The script mentions creating a form and handling file uploads, indicating that 'upload' is a central action in the tutorial.

💡PHP

PHP is a server-side scripting language designed for web development. It is used to create dynamic and interactive web pages. The video script suggests that the tutorial is focused on PHP, as it discusses creating a form and handling file uploads, which are common tasks in PHP for building web applications.

💡Form

A form in web development is a user interface element that allows users to input data, which is then sent to a server for processing. The script mentions creating a form for file uploads, indicating that it is an essential part of the video's tutorial on handling file uploads in PHP.

💡Server

A server in the context of web development is a computer system or software that provides resources or services to other computers, known as clients. The script refers to the server as the destination where uploaded files are stored, highlighting the server's role in managing data transfer and storage.

💡File Handling

File handling involves the processes of creating, reading, writing, and managing files in a system. The video script discusses file handling in the context of PHP, where the tutorial likely covers how to manage file uploads, process the files, and store them on the server.

💡Variables

In programming, variables are used to store data values. The script mentions using variables to store information about files, such as their names and paths. Variables play a critical role in the video's tutorial, as they are essential for processing and managing file data in PHP.

💡Methods

Methods in programming are functions that belong to an object. The script refers to methods in the context of checking for the existence of certain data transmission methods, such as POST, which is a common method used for sending data to a server in web forms.

💡POST

POST is an HTTP method used to send data to a server to create/update a resource. In the script, POST is mentioned as a method for transmitting file data from a form to a server, which is a typical use case for file uploads in web development.

💡File Paths

A file path is a reference to a location in a file system. It specifies the location of a file or a directory. The video script discusses file paths in the context of specifying where uploaded files should be stored on the server, which is an important aspect of file handling in PHP.

💡Error Handling

Error handling is the process of responding to and recovering from errors during the execution of a program. The script mentions error handling in the context of checking for errors in file uploads, which is a crucial part of ensuring that file uploads are processed correctly and securely in PHP.

💡FTP

FTP stands for File Transfer Protocol, a standard network protocol used for transferring files from one host to another over a TCP-based network. The script refers to using FTP for uploading files, indicating that it might be part of the tutorial on how to move files from a local system to a remote server.

Highlights

Introduction to uploading files in PHP

Creating a new folder for the project

Explanation of the file structure and naming conventions

Setting up a form for file uploads

Discussing the importance of file handling speed

Creating a folder to store company information

Integrating file upload functionality into a form

Explaining the process of handling file uploads on the server-side

Demonstrating how to test file upload functionality

Discussing the use of variables for file handling

Explaining how to check for data submission methods

Using server-side variables to handle file data

Highlighting the importance of error checking in file uploads

Providing a demonstration of the file upload form in action

Discussing the impact of file size on upload performance

Explaining how to save uploaded files to a desired folder

Using FTP to transfer files to a server

Concluding the tutorial with a summary of key points

Transcripts

play00:00

Hi

play00:03

[âm nhạc]

play00:05

xin chào các bạn đã quay trở lại cho tôi

play00:08

có học vest của mẹ này thì chúng ta sẽ

play00:11

đi tìm hiểu về cách upload file trong

play00:13

php mình sẽ tạo một cái Ford đời mới này

play00:17

cái Moderm lót

play00:20

ở trong fender strat để bị sẵn có pass

play00:23

file hoàn toàn

play00:26

trong có lời này thì mình sẽ tạo file

play00:28

đầu tiên đó là cái phone for our được

play00:31

chúng ta còn loa này là có lộc phó flash

play00:34

để làm con cái cái file xử lý kém đấy xử

play00:38

lý chậm bên cùng đó cho ta sẽ có một cái

play00:41

cái folder mới order để chứa những cái

play00:44

nhưng cái thông tin về chúng ta tại nên

play00:47

đặt tên là Pháp Loan

play00:49

rồi Như vậy là nơi sẽ có ba cái hoặc một

play00:52

cái nào cái folder chứa công ty đã này

play00:55

cái form này cái quá trình xử lý này còn

play00:59

ghi chúng ta hai iPhone trước ra tặng

play01:02

iPhone Action Đây là cái điều hướng đến

play01:05

sau khi mà cái phone sắp ít thì da sẽ

play01:08

biểu hưởng đến với trang xử lý cho pp

play01:10

rồi nghĩ mình về à

play01:14

a free size

play01:18

VP rồi

play01:21

Ở trong phòng này vì chúng ta đang đang

play01:25

học đã lắp vai ngay cái em thuốc ở đây

play01:27

những phút đây thay nó sẽ vắng vai rồi

play01:31

hay bằng file Tiếp theo là cái á

play01:35

cái sắp mới nhất con này Bức tượng Đây

play01:38

là bạn nên

play01:40

lại nên

play01:42

play01:43

hai thái cực kiếm tiền này là xóm nhất

play01:49

Bây giờ mình sẽ phát xem cái form là cái

play01:53

con như thế nào

play01:54

đã sẽ vào cặp file vào iPhone

play01:59

7 mình chọn một em để tải lên này cho nó

play02:03

đẹp

play02:04

play02:06

em anh chọn chất khác chụp ảnh

play02:14

anh tại nơi này à

play02:16

Ừ như vậy đó phải liên lạc thành công nó

play02:20

chuyển hướng đến cái chuyện hưởng đến

play02:22

cái Trang nè xử lí chấm sp đó sự nghiệp

play02:26

p p p

play02:28

ý thì cái tra xử lý cho bên này mình sẽ

play02:31

để cho ra một giọng

play02:34

EXO

play02:37

tra khởi nghĩ

play02:42

mình quay lại nhắm lại đó xanh cải sáng

play02:46

xử lý à

play02:49

trà

play02:50

xanh lên trang xử lý sao mình đang xử lý

play02:53

này chúng ta sẽ có

play02:56

một cái biến một cái miếng 8 cục đó là

play03:00

biến

play03:01

đôla file này họ đến Dota file này nó

play03:05

giống như là cái biến doris thành đô la

play03:07

chép mà chúng ta họ cũng phải trước

play03:08

những cái dữ liệu nó cho đẩy lên cho hấp

play03:12

này Nó sẽ được tiền nó sẽ lưu vào lưu

play03:15

thông tin vào cái biến for file này tôi

play03:17

defined lên chúng ta muốn lấy được công

play03:19

ty từ cái file tại đây chính là cách sử

play03:22

dụng biển nối wifi

play03:24

thì đầu tiên trước khi chúng ta lấy Biến

play03:27

loa phái chúng ta phải kiểm tra xem có

play03:29

cái phương thức về phương thức truyền dữ

play03:31

liệu là ghét hay làm bất làm xảy ra

play03:33

không như chúng ta vừa dùng ở bên này đó

play03:36

là chúng ta ấn xóm ít nó sẽ làm phương

play03:38

thức post hoặc cái đoàn kiểm tra có công

play03:42

thức tốt học từ ghép hay không Ừ nếu mà

play03:44

xảy ra một trong hai thức dậy thì ta mới

play03:46

có cái có mấy xét Việt cho les file này

play03:49

rồi tỷ lệ kiểm tra thì ta sẽ không ký

play03:53

tại đây là nếu mà Nó tồn tại là phủ định

play03:58

MC với em xin và nếu nó không bị lỗi này

play04:02

nó tình cảm

play04:03

với em thì có gì vừa cãi đôla rapper

play04:08

khalil Server này À cái biến siêu toàn

play04:13

cũng có chứa tất cả các thông tin đây

play04:15

Bạn có thể xem thêm vài biến thể ra sự

play04:18

trang vts Đó là quyển siêu chọn không

play04:23

sợ Vâng ạ

play04:25

khi họ như những cái biến cái biến đôla

play04:29

ghét thì Dota poster phim bên đấy nó đều

play04:32

nằm trong cái server Biên do xơ này để

play04:35

làm xong cái

play04:37

đây mình sẽ hiển vi quét

play04:42

bệnh khác Master

play04:46

Ai bảo nhìn thấy đây trong đội trong

play04:49

gara sever nó sẽ có cái vì parnassus và

play04:53

riêng biệt khác mẹ thước này nó chính là

play04:54

những cái phương thức là ghép tốt họ có

play04:58

tên khác 2 tốt đây là

play05:00

Ừ cái biến này là cái to nhất về siêu ô

play05:03

tô khổng lồ đấy và chúng ta sẽ xét là

play05:07

nếu mà có cái nhìn khác

play05:11

trên khác nghe sợ

play05:15

bị ghét là hết với hả có công thức phốt

play05:18

học phần thép phải ra đây là phương thức

play05:20

tốt học từ kép xảy ra thì chúng ta sẽ

play05:24

thực hiện các câu lệnh bên trong ít này

play05:27

họ để nếu mà nó có tồn tại vì nó không

play05:30

tồn tại vì nó không không thực hiện ít

play05:32

này thì coi như chưa có gì xảy ra

play05:35

rồi Nếu tồn tại cái này thì chúng ta sẽ

play05:37

cho

play05:39

có cái trạm trôi đi này

play05:42

free Green trời này là chúng ta sẽ để

play05:46

đôla vay ta sẽ in ra cái in ra cái

play05:51

delphi

play05:54

chuẩn bị đi

play05:57

rồi nó sẽ in ra cái refine cho nó có

play06:00

những cái à à

play06:02

Ê

play06:03

này ta sẽ quay lại cái xe này chúng ta

play06:06

ấn tải lên

play06:08

em còn thấy nó chưa dậy cái gì nó học

play06:10

cái bảng rộng

play06:12

bởi vì cái phone mà chúng ta đang có

play06:14

chút vấn đề nó cái chúng ta chúng ta tạo

play06:17

một cái form vọng nhát dao phải thêm cái

play06:20

kệ em em em cực hay thì cần thay bằng ở

play06:26

bằng mang thi pháp và thi pháp alldata

play06:30

họp khi nướng ta dùng cái for a thì

play06:33

chúng ta phải thêm cái em thay vào thì

play06:36

chúng ra mấy nhận được cái rất nhiều ông

play06:38

bên trong này Tại vì thằng Tại lên lại

play06:40

đi

play06:41

nó vẫn chưa vẫn chưa nhận thôi Mình sẽ

play06:45

thoát là để xem có vấn đề gì xảy ra nhé

play06:48

Cho lại file này

play06:50

Loan em vẫn tỏa này

play06:52

ở đây mọi người thấy nè cái tên file đây

play06:56

cái tên file đã được backlot nên vẽ URL

play06:59

trên nó đã dùng các phương thức là ghép

play07:02

có bởi vì chúng ta đã cho ta quên đã

play07:05

quên cái nghe thấy ghét tớ ở đây họ thể

play07:09

để làm tốt thì em ấy người ta mới chạy

play07:11

được còn ở kia là nó nhắn tự động nó

play07:14

nhặt lại vẫn là ghét rồi

play07:15

rồi chúng ta sẽ nó này

play07:19

cách chọn vai

play07:22

rồi lại lên người sẽ thấy là nó nhàn tức

play07:25

nó hiện ra cái thông tin về cái file thì

play07:27

đã khác đầu tiên đó là cái tên họ cái

play07:31

tên của anh thốt toàn thể cho anh phút

play07:33

đây họ cái tên cái bút là lên iOS này

play07:38

thì nó sẽ xuất hiện ở đây đó chính là

play07:42

cái kia thì khi có tiếp theo là cái giá

play07:45

trị nó nằm kế là thế mạnh về đâu đây cho

play07:49

cái bảng này nó có nên đấy full phát này

play07:51

hay này TP thêm một bên này và cái nỗi

play07:55

mà say được vẽ dung lượng đấy ạ

play07:59

Ừ nhưng mà người thấy là khi chúng ta

play08:02

lót lên

play08:03

cái cái pha này nó không hiện không Nó

play08:07

không nhảy vào cái cái Phật pháp đơn tại

play08:09

của mình nó không thể gặp Bởi vì khi

play08:12

người ta không nó sẽ nhảy lên cái đường

play08:14

dẫn này bạn thấy đơn giản này trên máy

play08:16

tính led Dell vào cái sang file nè trên

play08:20

máy tính mà không được ở cái prozac của

play08:22

mình

play08:23

thế nhưng bây giờ chúng ta nếu chúng ta

play08:25

muốn lưu các file cái phải cái ảnh chúng

play08:28

ta vừa tạo nên đấy vào cái vỏ có vào cái

play08:31

Kotex và vào cái pháp lót này chúng ta

play08:34

sẽ phải dùng đến một cái hàng đó là Ngô

play08:36

uploadfile Anh sẽ mở FPT này

play08:43

Toàn mình sẽ có một biến biến là vì sao

play08:48

vì sao

play08:52

và sẽ bằng mua võ wifi ở bên trong mua

play08:56

gói file này chap 2 cái tham số nhìn

play08:59

thấy hai cái số đấy cái đấy nhất là làm

play09:01

cái tên file để thứ hai nó là cái tiệm

play09:03

điểm đường dẫn mà mình muốn chuyển file

play09:06

tới ở bên đó là tên file thì mình sẽ có

play09:09

đôla vay và gọi là cái tên tên file này

play09:14

đó là in wifi và cái tên em của cái ảnh

play09:19

hot để chỉ rõ chỉ đích danh cả ảnh của

play09:23

chú Ý là muốn chuyển đi

play09:26

rồi trong này sẽ đặc biệt là

play09:29

Hello lắp ráp và tiếp theo Thế theo số

play09:34

tiếp theo đó là

play09:36

TP nên thì phải nên của anh

play09:46

đấy là tham số thứ nhất là tên file này

play09:48

là số thứ hai này tham số thứ hai là các

play09:51

đường dẫn đường dẫn thì đơn giản mình

play09:53

copy cái copy này

play09:56

đây nó có corepad đây phát là có khi đơn

play10:00

giản

play10:01

mình dán nó vào đây thôi I

play10:04

khi họ sẽ dán vào ra xong

play10:08

rồi bây giờ sau khi mà mình mua xả rác

play10:11

nơi mình chuyển sang ấy thì nó sẽ chán

play10:13

ghê trái quả về biến vì Giang này Bây

play10:17

giờ mình sẽ 35 nghìn Vì sao nhé và làm

play10:19

gì Vì sao đi

play10:21

chúc em làm mình

play10:24

hơi Mình sẽ thoát lại cái trang này

play10:28

Đây nó hiện ra luôn Cái Thế em mua các

play10:33

phải mình bên for Mà này bệnh viện nào

play10:35

mà biết xử lý tình huống xử lý

play10:37

ở với em mới xử lý này

play10:39

rồi mình sẽ nói lại cho một file này

play10:45

Ừ vợ karaoke cho máy ảnh Đã tải lên

play10:49

mọi người thấy nó đang là phone là lỗi

play10:52

phải mà cơ Ok mình xem lại chẳng có chút

play10:55

cái của Pháp của nó

play10:57

vào ai đây được dẫn này

play11:00

Ừ cái đường dẫn này dẫn này mình sau khi

play11:04

mình chuyển sang cái file mới mình về

play11:05

đặt cái tên cho nó mình đặt cái tên cho

play11:07

nó bằng cách là nối anh nhà mình sẽ nối

play11:11

tôi cãi à anh

play11:13

nói với cái tên Đây là cái tên cái cái

play11:17

nem này họ đi đũa thuat màn đêm mừng

play11:22

sinh nhật cái giá trị đã chỉ nó sẽ cái

play11:23

tên này Ừ thế thì mình sẽ nối với đd a

play11:26

five

play11:28

anh em mình xuống dòng cho nó nhìn cho

play11:30

rõ Này

play11:32

rồi với đôla file

play11:35

chạy xe Hero

play11:38

Of Clans và lên

play11:42

rồi

play11:44

mình sẽ chai này

play11:47

nó nó làm cho tai nghe phải lên nó và

play11:53

kết quả cho bé nó là Thu Loan lưu và

play11:56

biến nó có cái folder là tấm lót bạn

play12:00

nhìn thấy cái ảnh của mình gọi bởi ảnh

play12:03

đây thì em cứ nói là chuyện đó nước được

play12:05

cái file này thì đấy là cái cách là

play12:08

chúng ta áp 1 file lên và cho nó vào cái

play12:11

folder mà chúng ta mong muốn với cái

play12:13

hàng nào mua wifi ở

play12:16

Ừ rồi thì vào cũng sẽ kết thúc tại đây

play12:18

Xin chào và hẹn gặp

Rate This

5.0 / 5 (0 votes)

Related Tags
PHP TutorialFile UploadingWeb DevelopmentEfficiency TipsModern CodingServer HandlingData ProcessingWeb FormsTutorial SeriesPHP Techniques