Attached Files
Edited by Jaan, 08 June 2010 - 09:31 AM.
Guest_Jaan_*
|
|
|
Guest_eikukaan_*
#!CrunchBang Linux ~$ apt-get into it | #!(Statler:R20101205): OpenBox | Like Linux?
“The cure for boredom is curiosity. There is no cure for curiosity.”
Guest_Jaan_*
<?php
//This function will display your form
function form(){
echo "<form action='upload.php' enctype='multipart/form-data' method='post'>"
."Select your file for upload: <input type='file' name='file' size='30'> "
."<input type='submit' value='Upload' name='submit'>";
}
//This function will upload your file
function upload(){
//Let's collect all info into variables
$file = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$size = $_FILES['file']['size'];
$temp = $_FILES["file"]["tmp_name"];
//Let's set max file size to 2mb
$max_size = "2097152";
//Now set allowed file types
$allow_type_1 = "image/jpeg";
$allow_type_2 = "image/gif";
$allow_type_3 = "image/png";
$allow_type_4 = "image/bmp";
//If file size is bigger than 2mb than let's display an error
if($size > 2097152){
die("File is to big!");
}
//Now file type check, if file is not right we will display an error
if($type == $allow_type_1 or $type == $allow_type_2 or $type == $allow_type_3 or $type == $allow_type_4){
//If everything is good then let's upload
move_uploaded_file($temp, "upload/$file");
echo "Download: <a href='upload/$file'>Download $file</a>";
}else{
echo "Wrong file!";
}
}
if (empty($_POST['submit'])) {
form();
} else {
upload();
}
?>
Guest_Jaan_*
Guest_Jaan_*
#!CrunchBang Linux ~$ apt-get into it | #!(Statler:R20101205): OpenBox | Like Linux?
“The cure for boredom is curiosity. There is no cure for curiosity.”
Guest_Jaan_*
XaNaX said:
#!CrunchBang Linux ~$ apt-get into it | #!(Statler:R20101205): OpenBox | Like Linux?
“The cure for boredom is curiosity. There is no cure for curiosity.”