Ik heb een stukje code die kan alleen afbeeldingen uploaden.
Hoe kan ik de controle er uit halen zodat die alle soorten bestanden kan uploaden?
function thumb($File,$Size = 120,$ImgMap,$type){
if($type == "image/gif"){
$photo = imagecreatefromgif($ImgMap.'/'.$File);
}elseif($type == "image/pjpeg" or $type == "image/jpeg"){
$photo = imagecreatefromjpeg ($ImgMap.'/'.$File);
}elseif($type == "image/x-png" or $type == "image/png"){
$photo = imagecreatefrompng($ImgMap.'/'.$File);
}elseif($type == "application/pdf" or $type == "application/PDF"){
$photo = imagecreatefrompng($ImgMap.'/'.$File);
}else{
echo"Ongeldig type.<br \>";
return;
}
$photo_dimensions_width = imagesx ($photo);
$photo_dimensions_height = imagesy ($photo);
if ($photo_dimensions_width > $Size OR $photo_dimensions_height > $Size) {
if ($photo_dimensions_width == $photo_dimensions_height) {
$thumb_dimensions_width = $Size;
$thumb_dimensions_height = $Size;
}
elseif ($photo_dimensions_width > $photo_dimensions_height) {
$value = $photo_dimensions_width / $Size;
$thumb_dimensions_width = $Size;
$thumb_dimensions_height = round ($photo_dimensions_height / $value);
}
else {
$value = $photo_dimensions_height / $Size;
$thumb_dimensions_height = $Size;
$thumb_dimensions_width = round ($photo_dimensions_width / $value);
}
}
else {
$thumb_dimensions_width = $photo_dimensions_width;
$thumb_dimensions_height = $photo_dimensions_height;
}
$Cut = strrpos($File,'.');
$File = substr($File,0,$Cut);
$create_thumb = imagecreatetruecolor ($thumb_dimensions_width, $thumb_dimensions_height);
imagecopyresampled ($create_thumb, $photo, 0, 0, 0, 0, $thumb_dimensions_width, $thumb_dimensions_height, $photo_dimensions_width, $photo_dimensions_height);
ImageJpeg($create_thumb,$ImgMap.'/'.$File.".jpg",90);
Imagedestroy($photo);
}
?>
<?
if(isset($_GET['p'])){
if($_GET['p'] == "AddNews"){
if($_SERVER['REQUEST_METHOD'] == "POST"){
unset($_SESSION['Message']);
unset($_SESSION['Title']);
unset($_SESSION['link']);
unset($_SESSION['pdf']);
$_SESSION['Message'] = $_POST['Message'];
$_SESSION['Title'] = $_POST['Title'];
$_SESSION['link'] = $_POST['link'];
$_SESSION['pdf'] = $_POST['pdf'];
if(isset($_POST['AddFile'])){
if(!empty($_FILES['Picture']['tmp_name'])){
//Filename
$FileName = time() ."-".$_FILES['Picture']['name'];
// Toegestaande extensies opvragen
$ext = strtolower($ext);
$ext = explode(" ", $ext);
//Toegestaande types opvragen
$type = strtolower($type);
$type = explode(" ",$type);
$Pos = strrpos(strtolower($_FILES['Picture']['name']),'.');
$FileExt = substr (strtolower($_FILES['Picture']['name']), $Pos+1);
foreach($ext as $Value){
if($FileExt == $Value){
$ContrExt = TRUE;
}
}
foreach($type as $Value){
if(strtolower($_FILES['Picture']['type']) == $Value){
$ContrType = TRUE;
}
}
if($ContrType == TRUE && $ContrExt == TRUE){
if(move_uploaded_file($_FILES['Picture']['tmp_name'],"./".$ImgMap."/". $FileName)){
chmod("./".$ImgMap."/".$FileName,0644);
if(!empty($_POST['Thumb'])){
thumb($FileName,$_POST['Thumb'],$ImgMap,$_FILES['Picture']['type']);
$Cut = strrpos($FileName,'.');
$File = substr($FileName,0,$Cut);
$File.='.jpg';
if(mysql_query("INSERT INTO ".$SqlPrefix."pic (news_id,name,original,thumb) VALUES('". session_id() ."','". $FileName ."','".$_FILES['Picture']['name']."','".$File."')")){
$Disp = $_FILES['Picture']['name']." succesvol toegevoegd, en thumb succesvol gemaakt met een maximale grootte van ". $_POST['Thumb']."px";
}else{
$Disp = "MySql error:<br \>".mysql_error();
}
}else{
if(mysql_query("INSERT INTO ".$SqlPrefix."pic (news_id,name,original) VALUES('". session_id() ."','". $FileName ."','".$_FILES['Picture']['name']."')")){
$Disp = $_FILES['Picture']['name']." succesvol toegevoegd.";
}else{
$Disp = "MySql error:<br \>".mysql_error();
}
}
}else{
$Disp="Foto kon niet geupload worden, mogelijk bestaat de map img/ niet of heeft u te weinig rechten.";
}
}else{
$Disp="Bestand met incorrecte bestandsnaam of inhoud,".$FileExt."<br \>".$_FILES['Picture']['type'];
}
}else{
$Disp="Geen foto geselecteerd.";
}
}else{