10/10/2018, 09:37
Làm trang upload đơn giản
Mình đang làm 1 trang upload đơn giản. Khi upload file lên thì không được, bác nào sửa giúp mình với
Code:
Trang upload.html
<form enctype="multipart/form-data" action="uploader.php" method="get" name="frm1">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="upfile" type="file" />
<input type="submit" value="Upload" />
Trang uploader.php
<?php
$target_path = "upload/";
$target_path = $target_path .$_FILES['upfile']['name'];
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path))
{
echo "The file ". basename( $_FILES['upfile']['name'])." has been uploaded";
}
else
{
echo "Error!";
}
?>
Code:
Trang upload.html
<form enctype="multipart/form-data" action="uploader.php" method="get" name="frm1">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="upfile" type="file" />
<input type="submit" value="Upload" />
Trang uploader.php
<?php
$target_path = "upload/";
$target_path = $target_path .$_FILES['upfile']['name'];
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path))
{
echo "The file ". basename( $_FILES['upfile']['name'])." has been uploaded";
}
else
{
echo "Error!";
}
?>
Bài liên quan
mà theo như trên thì cậu chỉ kiểm tra cái code upload đó chứ đã thực thi nó chưa nhỉ ?
cậu thử bỏ code đó ra khỏi if và cho chạy xem sao .
<form enctype="multipart/form-data" action="uploader.php" method="get" name="frm1">
Ở đây ta phải dùng phương thức "post"