Thursday, 25 March 2010

Restrict file uploads allowed

In matters of uploaded files,usually the size of the file has been limited by the server.We can take a look at the php.ini file or via php post_max_size info for section.

form_upload.php

<form enctype="multipart/form-data" method="post" action="upload.php">
File yang diupload : <input type="file" name="fupload"><br>
<input type=submit value=Upload></form>


upload.php
<?php
$lokasi_file = $_FILES['fupload']['tmp_name'];
$nama_file = $_FILES['fupload']['name'];
$ukuran_file = $_FILES['fupload']['size'];
/ / If the file size> maximum size of the file
if ($file_size > $_POST[size_maks_file]){
echo "Upload Gagal !!! <br>
file size <b>$file_name</b> : $file_size bytes<br>
file size should not be > 1000000 bytes (1 Mb) <br>";
}else{
$directory_file = "files/$file_name";
move_uploaded_file($file_location,"$directory_file");
echo "File name : <b>$file_name</b> successfully uploads <br>";
echo "File size : <b>$file_size</b> bytes";

/ / Insert the file information into the database
mysql_connect("localhost","root","pajarmaning");
mysql_select_db("pintar");$input="INSERT INTO upload_file(file_name,file_size,description,directory)
VALUES('$file_name','$file_size','$description','$dirctoryi')";
mysql_query($input);
}?>


first run form_upload.php, click search to find the right files in the uplaod then click upload


Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

0 comments: on "Restrict file uploads allowed"

Post a Comment

Terima kasih atas kunjungan anda