1. index.php
2. Upload.php
3. Folder myfile
ในตัวอย่างต่อไปนี้จะเป็นการอัปโหลดไฟล์ เริ่มเเรกนั้นเรามาดูวิธีการสร้างไฟล์ เริ่มแรกนั้นทำการคลิกขวาที่ Source File จากนั้นเลือก new ตามด้วย php web Page และตั้งชื่อไฟล์ เป็น index และ upload เมื่อได้ตั้งชื่อไฟล์ดังรูปแล้วนั้นทำการคลิกขวาที่ สร้างโฟเดอร์ Source File จากนั้นเลือก new ตามด้วย folder และตั้งชื่อโฟเดอร์เป็น myfile ดังรูปภาพ
Code ในโฟลเดอร์ index
โค้ด: เลือกทั้งหมด
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<from name="from" method="post" action="upload.php" enctype="multip/from-data">
<input type="file" name="fileupload">
<input name="btnSubmit" type="submit" value="submit">
</from>
<?php
?>
</body>
</html>
โค้ด: เลือกทั้งหมด
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
if (move_uploaded_file($_FILES["fileUpload"]["tmp_name"],"myfile/".$_FILES["fileUpload"]["name"])) {
echo "อัปโหลดเรียบร้อย";
} else {
echo "ไม่สามารถอัปโหลดได้";
}
?>
</body>
</html>
สามารถดูข้อมูลเพิ่มเติมได้ที่ บทที่ 33 สอน PHP7 การสร้าง Upload Form ทำฟอร์มอัพโหลด HTML PHP