- Impact
- 62
PHP:
<?php
// Where the file is going to be placed temporarly
$target_path = "/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name']; // temp file
$target_path = "/uploads/";
$oldfile = basename($_FILES['uploadedfile']['name']);
// getting the extention
$pos = strpos($oldfile,".",0);
$ext = trim(substr($oldfile,$pos+1,strlen($oldfile))," ");
if(!$ext = "gif") {
if(!$ext = "jpg") {
if(!$ext = "png") {
if(!$ext = "bmp") {
echo "Dissallowed File Extension!";
echo "<p>Allowed extensions are .gif, .jpg, .png and .bmp</p>";
echo "<p><a href=\"Home.php\">Try Again</a></p>";
die();
}
}
}
}
//Check the size
if(!filesize($_FILES['uploadedfile']['name']) <= 1048576){
echo "File too large!";
echo "<p>Maximum size is 1MB</p>";
die();
}
//new file name exmaple for a profile image of a user
$newfile = Date("d:S:w:z:W:B:s:i") . "." . $ext;
// move the file to the final destination
$target_path = $target_path . basename($newfile);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
echo "<p>The URL is <b>http://www.ISC.tk/uploads/". $newfile . "</b></p>";
echo "<p>To view your file visit <b>http://www.ISC.tk/uploads/browseupload.php?file=". $newfile . "</b></p>";
echo "<p>We reserve the right to delete any file on our server.</p>";
echo "<p><a href=\"Home.php\">Upload Another</a></p>";
} else{
echo "There was an error uploading the file, please try again!";
echo "<p><a href=\"Home.php\">Try Again</a></p>";
}
?>
EDIT: I just checked again and the whole page dosnt work so I edited it in.