Skip to main content

PHP#20MySQL#16 - upfiles.php

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form method="post" enctype="multipart/form-data" name="form1" id="form1">
  <input type="hidden" name="MAX_FILE_SIZE" value="102400"/>
  <label for="upfile">File:</label>
  <input type="file" name="upfile" id="upfile">
  <input type="submit" name="submit" id="submit" value="Submit">
</form>
<?php
if(isset($_FILES['upfile']))
{
//Thư mục để chứa file:
$target="files/";
//lấy tên:
$filename=basename($_FILES['upfile']['name']); //abc.jpg đang ở c:/hinh/abc.jpg
$target=$target.$filename;
//kiểm tra file đã có chưa:
if(file_exists($target)) echo "File đã tồn tại!";
else echo "File chưa có!";
//Kiểm tra loại file cần up:
if(preg_match("/\.(jpg|gif|bmp)$/i",$filename))
echo "Đây là file ảnh!";
else echo "Đây không phải file ảnh!";
//up file:
if(move_uploaded_file($_FILES['upfile']['tmp_name'],$target))
echo "$filename đã được up lên thành công!";
else echo "Upload thất bại!";
// size: kích thước của file up lên
//type: kiểu của tập tin:
}
?>
</body>
</html>

Comments

Popular posts from this blog

PHP#17MySQL#13 - tin cũ hơn

//chitiettin.php <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php if(isset($_GET['idTin'])) { $idTin=$_GET['idTin']; include("connect.php"); $sl="select idLT, TieuDe, TomTat, Content from tin where idTin=$idTin"; $kq=mysqli_query($link,$sl); $d=mysqli_fetch_array($kq) ?> <h1 align="center"><?php echo $d['TieuDe'];?></h1> <div><?php echo $d['TomTat'];?></div> <div><?php echo $d['Content'];?></div> <?php }?> <p> các tin cũ hơn(lấy 5 tin cũ hơn và cùng loại tin với tin đang mở, sắp xếp từ mới đến cũ </p> <ul> <?php  $sltc="select * from tin where AnHien=1 and idLT={$d['idLT']} and idTin < $idTin order by idTin DESC limit 0,5"; $kqtc=mysqli_query($link,$sltc); while($dtc=...

PHP#33MySQL#29 - Đếm lượt truy cập (KẾT THÚC KHÓA HỌC)

//hitcounter.php <?php session_start();  ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php  include("../connect.php"); //cập nhật số luowhtj truy cập: $sl="update counter set cnt=cnt+1"; mysqli_query($link,$sl); //Lấy dữ liệu số lượt truy cập để hiển thị ra web: $sl2="select * from counter"; $kq=mysqli_query($link,$sl2); $d=mysqli_fetch_array($kq); //Định dạng: $chuoi=str_pad($d['cnt'],6,"0",STR_PAD_LEFT); $luottrycap=""; for($i=0;$i<strlen($chuoi);$i++) { $tam=substr($chuoi,$i,1); $luottrycap.="<img src='images/$tam.png'/>"; } /*-Khi user truy cập vào website: +lần đầu tuy cập: Lưu thông tin của user lên csdl +Sau lần đầu tiên: cập nhtaaj lastvisit - Xóa các dòng dữ liệu quá 1 phút (Quy ước thời gian để khẳng định online hay offline: 1 phút) - Thống kê số liệu người dùng o...

2 (giao diện Visual C#) Solution Explorer