PHP Image uploader

Gestart doorXrayz5 reacties69 weergaven

6 berichten · pagina 1 van 1

Xrayz

Lid · Topicstarter

Berichten
245
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik was bezig met een PHP script om images te uploaden. Ik had gekozen voor jpg,png,jpeg,gif maar op de een of andere manier werkt alleen .gif.
______________
Dit is de php zelf (zonder html):

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "
";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "
";
echo "Type: " . $_FILES["file"]["type"] . "
";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
";

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>

Hoe kan ik ervoor zorgen dat .jpg/jpeg/png ook werkt?

Bedankt alvast.
0
Berichten
2.609
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
|| ($_FILES["file"]["type"] == ".jpg")

Zo denk ik xd
0
Xrayz

Lid · Topicstarter

Berichten
245
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Heb ik net geprobeerd bij allemaal, Invalid file confused
Edit: het is toch niet zon uitgebreid script, is er iemand geintereseerd in een upload script te maken voor mij? Je krijgt er natuurlijk punten voor biggrin
Meer info per P.B.
0
Berichten
5.897
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
kijk gewoon op phphulp of sitemasters.be daar vind je er genoeg wink
0
Berichten
2.609
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ach.. Ik heb er nog 1 liggen:

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]//verander de onderstaande gegevens [/COLOR]

[COLOR= #0000BB]$locatie[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #DD0000]"uploads/"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//of een andere map, vergeet niet de w-rechten [/COLOR]
[COLOR= #0000BB]$toegestaan[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"jpg, gif, png, jpeg, bmp, PNG"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// extensies die toegestaan zijn [/COLOR]
[COLOR= #0000BB]$max_size[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]9999999999999999[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//maximale grootte van het bestand in bytes

//stop met veranderen [/COLOR]

[URL="http://www.php.net/set_time_limit"]set_time_limit[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]);[/COLOR] 

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]upload[/COLOR][COLOR= #007700]])) 
{[/COLOR] 
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/is_uploaded_file"]is_uploaded_file[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bestand[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]tmp_name[/COLOR][COLOR= #007700]])) 
{[/COLOR] 
[COLOR= #0000BB]$extensie_bestand[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/pathinfo"]pathinfo[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bestand[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]name[/COLOR][COLOR= #007700]]);[/COLOR] 
[COLOR= #0000BB]$extensie_bestand[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$extensie_bestand[/COLOR][COLOR= #007700][[/COLOR]extension[COLOR= #007700]];[/COLOR] 

[COLOR= #0000BB]$extensies_toegestaan[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]", "[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$toegestaan[/COLOR][COLOR= #007700]);[/COLOR] 

[URL="http://www.php.net/for"]for[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$i[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #0000BB]$i[/COLOR] [COLOR= #007700]<[/COLOR] [URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$extensies_toegestaan[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #0000BB]$i[/COLOR][COLOR= #007700]++) 
{[/COLOR] 
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$extensies_toegestaan[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]"$extensie_bestand"[/COLOR][COLOR= #007700]) 
{[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/file_exists"]file_exists[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]uploads/[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bestand[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]name[/COLOR][COLOR= #007700]]))
{[/COLOR]
[URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Er bestaat al een bestand met die naam."[/COLOR][COLOR= #007700]);
}[/COLOR]

[COLOR= #0000BB]$ok[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]; 
} 
}[/COLOR] 

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$ok[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]) 
{[/COLOR] 
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bestand[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]size[/COLOR][COLOR= #007700]]>[/COLOR][COLOR= #0000BB]$max_size[/COLOR][COLOR= #007700]) 
{[/COLOR] 
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Het bestand is te groot, de maximale grootte is: <b>$max_size</b>"[/COLOR][COLOR= #007700];[/COLOR] 
[URL="http://www.php.net/exit"]exit[/URL][COLOR= #007700]; 
}[/COLOR] 



[URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/move_uploaded_file"]move_uploaded_file[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bestand[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]tmp_name[/COLOR][COLOR= #007700]],[/COLOR] 
[COLOR= #0000BB]$locatie[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bestand[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]name[/COLOR][COLOR= #007700]])) 
{[/COLOR] 
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"het bestand kan niet worden verplaatst"[/COLOR][COLOR= #007700];[/COLOR] 
[URL="http://www.php.net/exit"]exit[/URL][COLOR= #007700]; 
}[/COLOR] 
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Het bestand "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bestand[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]name[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]" is geupload<br> 
<a href="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$locatie[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bestand[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]name[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]" target=_blank>Klik hier om het te bekijken</a></td>"[/COLOR][COLOR= #007700]; 
}[/COLOR] 
[URL="http://www.php.net/else"]else[/URL] 
[COLOR= #007700]{[/COLOR] 
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Verkeerde extentie, de toegestane extensies zijn: <b>$toegestaan</b> *NEEM CONTACT MET NICKJEXX OP!*"[/COLOR][COLOR= #007700]; 
} 
}[/COLOR] 
[URL="http://www.php.net/else"]else[/URL] 
[COLOR= #007700]{[/COLOR] 
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Het uploaden is mislukt *NEEM CONTACT MET NICKJEXX OP!*"[/COLOR][COLOR= #007700]; 
} 

}[/COLOR] 

?>
0
Xrayz

Lid · Topicstarter

Berichten
245
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bedankt biggrinHet is inmiddels dus gelukt.
Slotje
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren