Code wil niet uploaden
brantjeNL - 10/09/2004 18:34
Nieuw lid
Hoi
deze codes heb ik ergens van internet geplukt
echter, hij doet het niet!
<?php
//Get the number of files to be uploaded
$num = $_POST['num'];
//Start the Loop
for ($x = 1; $x <= $num; $x++)
{
//Make sure a file has been selected for upload
if (is_uploaded_file($_FILES['file'.$x]['tmp_name']))
{
//Get the size of the current file
$size = $_FILES['file'.$x]['size'];
//Make sure that this file is <= to 100KB
if ($size <= 50000000)
{
//Move the uploaded file
if (move_uploaded_file($_FILES['file'.$x]['tmp_name'],'uploads/'.$_FILES['file'.$x]['name']))
{
//Display message
echo "File: ".$_FILES['file'.$x]['name'] . " uploaded.<BR>";
}
else
{
//Unable to move file
echo "File: ".$_FILES['file'.$x]['name']. " error moving file.<BR>";
}
}
else
{
//File too large
echo "File: " . $_FILES['file'.$x]['name'] . "File Too Large.<BR>";
}
}
else
{
//No file selected
echo "No File Selected.<BR>";
}
} //End of loop
?>
<?php
//Get the number of files to be uploaded
$num = $_POST [ 'num' ] ;
//Start the Loop
for ( $x = 1 ; $x <= $num ; $x ++ )
{
//Make sure a file has been selected for upload
{
//Get the size of the current file
$size = $_FILES [ 'file' . $x ] [ 'size' ] ;
//Make sure that this file is <= to 100KB
if ( $size <= 50000000 )
{
//Move the uploaded file
if ( move_uploaded_file ( $_FILES [ 'file' . $x ] [ 'tmp_name' ] , 'uploads/' . $_FILES [ 'file' . $x ] [ 'name' ] ) ) {
//Display message
echo "File: " . $_FILES [ 'file' . $x ] [ 'name' ] . " uploaded.<BR>" ;
}
else
{
//Unable to move file
echo "File: " . $_FILES [ 'file' . $x ] [ 'name' ] . " error moving file.<BR>" ; }
}
else
{
//File too large
echo "File: " . $_FILES [ 'file' . $x ] [ 'name' ] . "File Too Large.<BR>" ;
}
}
else
{
//No file selected
echo "No File Selected.<BR>" ;
}
} //End of loop
?>
Wat is de fout????
Groeten brantje
p.s.
Kan ik hier ook een image uploader van maken voor
jpg|jpeg|bmp|gif|png
?
27 antwoorden
Gesponsorde links
DRUNK - 10/09/2004 18:57
PHP gevorderde
wat werkt er niet? krijg je ook foutmeldingen...of gebeurd er helemaal niets?
brantjeNL - 10/09/2004 18:58
Nieuw lid
Er gebeurd niets
geen fout meldingen niets
DRUNK - 10/09/2004 19:24 (laatste wijziging 10/09/2004 19:31)
PHP gevorderde
zet het ondersaande formulier in een file (upload_form.htm ofzo) en zet de code die je hier boven gepost heb in een bestand: upload.php. Ga nu met je browser naar: http://je domein of ip/upload_form.htm, vul het in en klik op upload. Werkt dat?
<html>
<head>
<title>test form</title>
</head>
<body>
<form name="upload" action="upload.php" enctype="multipart/form-data" method="POST">
<input type="text" name="num" maxlength="3" size="3" />
<input type="file" name="file1" />
<input type="file" name="file2" />
<input type="file" name="file3" />
<input type="file" name="file4" />
<input type="file" name="file5" />
<input type="submit" name="upl" value="upload" />
</form>
</body>
</html>
< html>
< head>
< title> test form</ title>
</ head>
< body>
< form name= "upload" action= "upload.php" enctype= "multipart/form-data" method= "POST" >
< input type= "text" name= "num" maxlength= "3" size= "3" />
< input type= "file" name= "file1" />
< input type= "file" name= "file2" />
< input type= "file" name= "file3" />
< input type= "file" name= "file4" />
< input type= "file" name= "file5" />
< input type= "submit" name= "upl" value= "upload" />
</ form>
</ body>
</ html>
!!!let er wel op dat je upload directory (./uploads) CHMOD 0777 is!!!
brantjeNL - 10/09/2004 20:14
Nieuw lid
Ok zal ff kijke
brantjeNL - 10/09/2004 20:22
Nieuw lid
Nope werkt niet
ik heb alle vakjes aangevinkt
deze codes gebruik ik
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><?php
//Get the number of files to be uploaded
$num = $_POST['num'];
//Start the Loop
for ($x = 1; $x <= $num; $x++)
{
//Make sure a file has been selected for upload
if (is_uploaded_file($_FILES['file'.$x]['tmp_name']))
{
//Get the size of the current file
$size = $_FILES['file'.$x]['size'];
//Make sure that this file is <= to 100KB
if ($size <= 50000000)
{
//Move the uploaded file
if (move_uploaded_file($_FILES['file'.$x]['tmp_name'],'uploads/'.$_FILES['file'.$x]['name']))
{
//Display message
echo "File: ".$_FILES['file'.$x]['name'] . " uploaded.<BR>";
}
else
{
//Unable to move file
echo "File: ".$_FILES['file'.$x]['name']. " error moving file.<BR>";
}
}
else
{
//File too large
echo "File: " . $_FILES['file'.$x]['name'] . "File Too Large.<BR>";
}
}
else
{
//No file selected
echo "No File Selected.<BR>";
}
} //End of loop
?>
</body>
</html>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><?php
//Get the number of files to be uploaded
$num = $_POST [ 'num' ] ;
//Start the Loop
for ( $x = 1 ; $x <= $num ; $x ++ )
{
//Make sure a file has been selected for upload
{
//Get the size of the current file
$size = $_FILES [ 'file' . $x ] [ 'size' ] ;
//Make sure that this file is <= to 100KB
if ( $size <= 50000000 )
{
//Move the uploaded file
if ( move_uploaded_file ( $_FILES [ 'file' . $x ] [ 'tmp_name' ] , 'uploads/' . $_FILES [ 'file' . $x ] [ 'name' ] ) ) {
//Display message
echo "File: " . $_FILES [ 'file' . $x ] [ 'name' ] . " uploaded.<BR>" ;
}
else
{
//Unable to move file
echo "File: " . $_FILES [ 'file' . $x ] [ 'name' ] . " error moving file.<BR>" ; }
}
else
{
//File too large
echo "File: " . $_FILES [ 'file' . $x ] [ 'name' ] . "File Too Large.<BR>" ;
}
}
else
{
//No file selected
echo "No File Selected.<BR>" ;
}
} //End of loop
?>
</body>
</html>
<html>
<head>
<title>test form</title>
</head>
<body>
<form name="upload" action="upload.php" enctype="multipart/form-data" method="POST">
<input type="text" name="num" maxlength="3" size="3" />
<input type="file" name="file1" />
<input type="file" name="file2" />
<input type="file" name="file3" />
<input type="file" name="file4" />
<input type="file" name="file5" />
<input type="submit" name="upl" value="upload" />
</form>
</body>
</html>
< html>
< head>
< title> test form</ title>
</ head>
< body>
< form name= "upload" action= "upload.php" enctype= "multipart/form-data" method= "POST" >
< input type= "text" name= "num" maxlength= "3" size= "3" />
< input type= "file" name= "file1" />
< input type= "file" name= "file2" />
< input type= "file" name= "file3" />
< input type= "file" name= "file4" />
< input type= "file" name= "file5" />
< input type= "submit" name= "upl" value= "upload" />
</ form>
</ body>
</ html>
XenoX - 10/09/2004 20:24 (laatste wijziging 10/09/2004 20:26)
PHP expert
<html>
<head>
<title>test form</title>
</head>
<body>
<form name="upload" action="upload.php" enctype="multipart/form-data" method="POST">
<!-- <input type="text" name="num" maxlength="3" size="3" /> -->
<input type="file" name="file1" />
<input type="file" name="file2" />
<input type="file" name="file3" />
<input type="file" name="file4" />
<input type="file" name="file5" />
<input type="hidden" name="num" value="5" />
<input type="submit" name="upl" value="upload" />
</form>
</body>
</html>
< html>
< head>
< title> test form</ title>
</ head>
< body>
< form name= "upload" action= "upload.php" enctype= "multipart/form-data" method= "POST" >
<!-- < input type= "text" name= "num" maxlength= "3" size= "3" /> -->
< input type= "file" name= "file1" />
< input type= "file" name= "file2" />
< input type= "file" name= "file3" />
< input type= "file" name= "file4" />
< input type= "file" name= "file5" />
< input type= "hidden" name= "num" value= "5" />
< input type= "submit" name= "upl" value= "upload" />
</ form>
</ body>
</ html>
Gebruik deze html code.
b4nkr0bz0r - 10/09/2004 20:25 (laatste wijziging 10/09/2004 20:26)
PHP gevorderde
iig je begint met de <html> tag zet er php in en sluit met </html>
geen zin dus je moet dat laatste scriptje dus in de html tag zetten:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><?php
//Get the number of files to be uploaded
$num = $_POST['num'];
//Start the Loop
for ($x = 1; $x <= $num; $x++)
{
//Make sure a file has been selected for upload
if (is_uploaded_file($_FILES['file'.$x]['tmp_name']))
{
//Get the size of the current file
$size = $_FILES['file'.$x]['size'];
//Make sure that this file is <= to 100KB
if ($size <= 50000000)
{
//Move the uploaded file
if (move_uploaded_file($_FILES['file'.$x]['tmp_name'],'uploads/'.$_FILES['file'.$x]['name']))
{
//Display message
echo "File: ".$_FILES['file'.$x]['name'] . " uploaded.<BR>";
}
else
{
//Unable to move file
echo "File: ".$_FILES['file'.$x]['name']. " error moving file.<BR>";
}
}
else
{
//File too large
echo "File: " . $_FILES['file'.$x]['name'] . "File Too Large.<BR>";
}
}
else
{
//No file selected
echo "No File Selected.<BR>";
}
} //End of loop
?>
<form name="upload" action="upload.php" enctype="multipart/form-data" method="POST">
<input type="text" name="num" maxlength="3" size="3" />
<input type="file" name="file1" />
<input type="file" name="file2" />
<input type="file" name="file3" />
<input type="file" name="file4" />
<input type="file" name="file5" />
<input type="submit" name="upl" value="upload" />
</form>
</body>
</html>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><?php
//Get the number of files to be uploaded
$num = $_POST [ 'num' ] ;
//Start the Loop
for ( $x = 1 ; $x <= $num ; $x ++ )
{
//Make sure a file has been selected for upload
{
//Get the size of the current file
$size = $_FILES [ 'file' . $x ] [ 'size' ] ;
//Make sure that this file is <= to 100KB
if ( $size <= 50000000 )
{
//Move the uploaded file
if ( move_uploaded_file ( $_FILES [ 'file' . $x ] [ 'tmp_name' ] , 'uploads/' . $_FILES [ 'file' . $x ] [ 'name' ] ) ) {
//Display message
echo "File: " . $_FILES [ 'file' . $x ] [ 'name' ] . " uploaded.<BR>" ;
}
else
{
//Unable to move file
echo "File: " . $_FILES [ 'file' . $x ] [ 'name' ] . " error moving file.<BR>" ; }
}
else
{
//File too large
echo "File: " . $_FILES [ 'file' . $x ] [ 'name' ] . "File Too Large.<BR>" ;
}
}
else
{
//No file selected
echo "No File Selected.<BR>" ;
}
} //End of loop
?>
<form name="upload" action="upload.php" enctype="multipart/form-data" method="POST">
<input type="text" name="num" maxlength="3" size="3" />
<input type="file" name="file1" />
<input type="file" name="file2" />
<input type="file" name="file3" />
<input type="file" name="file4" />
<input type="file" name="file5" />
<input type="submit" name="upl" value="upload" />
</form>
</body>
</html>
brantjeNL - 11/09/2004 09:03
Nieuw lid
Heb ik als us een x gedaan.
Maar ik snap er geen bal van.
Maar dat scriptje doet het niet.
Hoe kan dat op een ander fora zeiden ze dat het aan een { of }
kon liggen.
brantjeNL - 11/09/2004 09:14
Nieuw lid
Ok heb een code van hier gebruikt.
Maar
Hoe kan ik deze nu gebruiken voor Images??
<?php
error_reporting(E_ALL);
$map = "uploads/"; // Map waar alles geupload wordt
function upload_file($fTmp, $fNew) {
if(file_exists($fNew)) {
return false;
} else {
copy($fTmp, $fNew);
return true;
}
}
if(IsSet($_POST['submit'])) {
for($i = 0; $i < count($_FILES['bestand']['name']); $i++) {
if(IsSet($_FILES['bestand']['name'][$i]) && is_uploaded_file($_FILES['bestand']['tmp_name'][$i])) {
if(!upload_file($_FILES['bestand']['tmp_name'][$i], $map.$_FILES['bestand']['name'][$i])) {
$error = true;
}
}
}
if(IsSet($error)) {
echo "Mislukt!";
} else {
echo "Gelukt!";
}
} else {
if(IsSet($_POST['aantal'])) {
$aantal = $_POST['aantal'];
} else {
$aantal = 10;
}
?>
<?php
$map = "uploads/" ; // Map waar alles geupload wordt
function upload_file( $fTmp , $fNew ) {
return false ;
} else {
return true ;
}
}
if ( IsSet ( $_POST [ 'submit' ] ) ) { for ( $i = 0 ; $i < count ( $_FILES [ 'bestand' ] [ 'name' ] ) ; $i ++ ) { if ( ! upload_file( $_FILES [ 'bestand' ] [ 'tmp_name' ] [ $i ] , $map . $_FILES [ 'bestand' ] [ 'name' ] [ $i ] ) ) {
$error = true ;
}
}
}
} else {
}
} else {
if ( IsSet ( $_POST [ 'aantal' ] ) ) { $aantal = $_POST [ 'aantal' ] ;
} else {
$aantal = 10 ;
}
?>
brantjeNL - 11/09/2004 12:42
Nieuw lid
Hoe kan ik dat doen?
brantjeNL - 11/09/2004 12:42
Nieuw lid
Hoe kan ik dat doen?
DRUNK - 11/09/2004 12:48
PHP gevorderde
nou je zou een plaatje kunnen selecteren en uploaden.
Carpmadness - 11/09/2004 12:48
PHP interesse
Ik vraag me af waar hij de images stored?
brantjeNL - 11/09/2004 13:07
Nieuw lid
ja maar ik wil niet dat ze exes gaan uploadenzo
wat is namelijk een foto server
jpg jpeg bmp gif png
die alleen
doe kan ik die functie in bakken.
help me ff als je een banner hebt zet ik die wel f op de site
hij word nu al druk bezocht.
in de beta versie maar daar heb ik deze code
<?PHP
// In welke map komen de bestanden ? ( zorg dat deze de permissies 777 krijgt )
$map = "uploads/";
// Wat is de maximale groote van het bestand in bytes ( 1 kb = 1000 bytes )
$max = "5000000";
// Welke extensies kunnen er worden geupload ( als alles mag dan niks invullen )
$ext = "jpg gif png jpeg bmp";
if ($Uploaden){
if (!$bestand)
print ("Geef een bestand op!");
else{
$bestand2 = explode("\\", $bestand_name);
$laatste = count($bestand2) - 1;
$bestand2 = "$bestand2[$laatste]";
$bestand3 = explode(".", $bestand2);
$laatste = count($bestand3) - 1;
$bestand3 = "$bestand3[$laatste]";
$bestand3 = strtolower($bestand3);
$ext = strtolower($ext);
$ext = explode(" ", $ext);
$aantal = count($ext);
for ($tel = 0;$tel < $aantal; $tel++){
if ($bestand3 == $ext[$tel]){
$extfout = "nee";
}
}
if (!$extfout){
print ("Het bestand \"$bestand2\" kan niet worden geupload omdat de extensie niet is toegestaan!");
}
else
{
if ($bestand_size > $max)
print ("Het bestand \"$bestand2\" is groter dan $max bytes!");
else
{
copy($bestand, "$map$bestand2");
print ("Het bestand \"$bestand2\" is met succes geupload!<br><BR><a href=\"dir.php\">Ga terug</a>");
}
}
}
}
print ("<form method=post action=uploaden.php enctype=multipart/form-data>
Bestand: <input type=file name=bestand><br><br>
<input type=submit name=Uploaden value=Uploaden></form>");
?>
<?PHP
// In welke map komen de bestanden ? ( zorg dat deze de permissies 777 krijgt )
$map = "uploads/" ;
// Wat is de maximale groote van het bestand in bytes ( 1 kb = 1000 bytes )
$max = "5000000" ;
// Welke extensies kunnen er worden geupload ( als alles mag dan niks invullen )
$ext = "jpg gif png jpeg bmp" ;
if ( $Uploaden ) {
if ( ! $bestand )
print ( "Geef een bestand op!" ) ; else {
$bestand2 = explode ( "\\" , $bestand_name ); $laatste = count($bestand2 ) - 1;
$bestand2 = "$bestand2 [ $laatste ] ";
$bestand3 = explode(". ", $bestand2 );
$laatste = count($bestand3 ) - 1;
$bestand3 = "$bestand3 [ $laatste ] ";
$bestand3 = strtolower($bestand3 );
$ext = strtolower($ext );
$ext = explode(" ", $ext );
$aantal = count($ext );
for ($tel = 0;$tel < $aantal ; $tel ++){
if ($bestand3 == $ext [$tel ]){
$extfout = " nee";
}
}
if (!$extfout ){
print (" Het bestand \"$bestand2 \" kan niet worden geupload omdat de extensie niet is toegestaan!" ) ;
}
else
{
if ( $bestand_size > $max )
print ( "Het bestand \" $bestand2 \" is groter dan $max bytes!" ) ; else
{
copy ( $bestand , "$map $bestand2 " ) ; print ( "Het bestand \" $bestand2 \" is met succes geupload!<br><BR><a href=\" dir.php\" >Ga terug</a>" ) ;
}
}
}
}
print ( "<form method=post action=uploaden.php enctype=multipart/form-data> Bestand: <input type=file name=bestand><br><br>
<input type=submit name=Uploaden value=Uploaden></form>" ) ;
?>
deze is voor de beta maar omdat ik meer uploads wil
vind ik deze beter teminste als ie voor images aangepast kan worden
brantjeNL - 11/09/2004 13:08
Nieuw lid
@carpmadness
$map = "uploads/"; // Map waar alles geupload wordt
daar gooit ie alles in
DRUNK - 11/09/2004 13:15 (laatste wijziging 11/09/2004 13:16)
PHP gevorderde
je kan naar het mime-type kijen dmv. $_FILES['userfile']['type']:
<?php
if ($_FILES['userfile']['type'] != 'image/gif') {
die('je mag alleen .gif bestanden uploaden');
}
?>
<?php
if ( $_FILES [ 'userfile' ] [ 'type' ] != 'image/gif' ) {
die ( 'je mag alleen .gif bestanden uploaden' ) ; }
?>
je kan dit natuurlijk altijd veranderen of meer mime-types toevoegen.
http://www.php....upload.php /
brantjeNL - 11/09/2004 14:18
Nieuw lid
doe kan ik dat dan invoegen?
DRUNK - 11/09/2004 14:31
PHP gevorderde
uuh de code die je boven gepost had controleerd al op de extentie, persoonlijk vind ik dit geen goed script zitten te veel 'raare' dingen in, als ik u was zo ik eers even beginnen php te leren hier op sitemasters.be (http://sitemasters.be/index.php?pagina=tutorials/tutorials&cat=4) dan weet je ook waar je mee bezig bent. Dan kan je zelf een upload script schrijven, als je dan nog vragen heb hoor ik het wel.
brantjeNL - 11/09/2004 15:23
Nieuw lid
ja maar die hoor bij de beta
en die gaat dus weg maar de code die hier vandaan kwam moet op
file types controleren
brantjeNL - 11/09/2004 15:25
Nieuw lid
ja maar die hoor bij de beta
en die gaat dus weg maar de code die hier vandaan kwam moet op
file types controleren
DRUNK - 11/09/2004 15:55 (laatste wijziging 11/09/2004 16:07)
PHP gevorderde
kan je hier wat mee?
<?php error_reporting(E_ALL);
/**
* map waar de uploads geplaatst worden (!chmod 0777!)
*/
$map = './uploads/';
/**
* array met de toegestane upload types
*/
$types = array(
'image/gif',
'image/jpeg',
'image/png',
'image/bmp'
);
if(isset($_POST['submit'])) {
for($i = 0; $i < count($_FILES['bestand']['name']); $i++) {
if(isset($_FILES['bestand']['name'][$i]) && is_uploaded_file($_FILES['bestand']['tmp_name'][$i])) {
if (!in_array($_FILES['bestand']['type'][$i], $types)) {
die('dit bestandsformaat is niet toegestaan!');
}
if(!move_uploaded_file($_FILES['bestand']['tmp_name'][$i], $map.$_FILES['bestand']['name'][$i])) {
echo 'mislukt!';
}
else {
echo 'gelukt!';
}
}
}
}
else {
if(isset($_POST['aantal'])) {
$aantal = $_POST['aantal'];
}
else {
$aantal = 10;
}
}
?>
/**
* map waar de uploads geplaatst worden (!chmod 0777!)
*/
$map = './uploads/' ;
/**
* array met de toegestane upload types
*/
'image/gif' ,
'image/jpeg' ,
'image/png' ,
'image/bmp'
) ;
if ( isset ( $_POST [ 'submit' ] ) ) { for ( $i = 0 ; $i < count ( $_FILES [ 'bestand' ] [ 'name' ] ) ; $i ++ ) { if ( ! in_array ( $_FILES [ 'bestand' ] [ 'type' ] [ $i ] , $types ) ) { die ( 'dit bestandsformaat is niet toegestaan!' ) ; }
if ( ! move_uploaded_file ( $_FILES [ 'bestand' ] [ 'tmp_name' ] [ $i ] , $map . $_FILES [ 'bestand' ] [ 'name' ] [ $i ] ) ) { }
else {
}
}
}
}
else {
if ( isset ( $_POST [ 'aantal' ] ) ) { $aantal = $_POST [ 'aantal' ] ;
}
else {
$aantal = 10 ;
}
}
?>
ps: 1x posten is genoeg hoor
brantjeNL - 12/09/2004 07:41 (laatste wijziging 12/09/2004 07:41)
Nieuw lid
@ Drunk hij doet het niet
ik zie alleen een wit scherm meer niet
staat een laadbalkje allen Done
brantjeNL - 12/09/2004 14:45
Nieuw lid
De gene die de peste oplossing heeft krijgt een plek voor een banner op mijn site
:cool:
DRUNK - 12/09/2004 15:39 (laatste wijziging 12/09/2004 19:41)
PHP gevorderde
ja niet gek dat het niet werkt, zit geen form bij. Hier een werkende versie, je kan tot maximaal 999 bestanden uloaden, dit lijkt mij wel genoeg :
<?php error_reporting(E_ALL); ?>
<html>
<head>
<title>test form</title>
</head>
<body>
<?php
/**
* map waar de uploads geplaatst worden (!chmod 0777!)
*/
$map = './uploads/';
/**
* array met de toegestane upload types
*/
$types = array(
'image/gif',
'image/jpeg',
'image/png',
'image/bmp'
);
/**
* aantal bestanden te uploaden:
* default = 5
* verhogen of verlagen varvang dan de 5
*/
$aantal = (empty($_POST['aantal'])) ? 5 : $_POST['aantal'];
echo '<form name="aantal" action="" method="POST">';
echo 'aantal bestanden: <input type="text" name="aantal" size="3" maxlength="3" />';
echo '<input type="submit" name="apply" value="toepassen" />';
echo '</form><hr /><br />';
if(!isset($_POST['submit'])) {
echo '<form name="upload" action="upload.php" enctype="multipart/form-data" method="POST">';
for ($i = 1; $i <= $aantal; $i++) {
if ($i < 10) {
echo 'Bestand 00' . $i . ': <input type="file" name="bestand[]" /><br />';
}
else if ($i < 100 && $i >= 10) {
echo 'Bestand 0' . $i . ': <input type="file" name="bestand[]" /><br />';
}
else {
echo 'Bestand ' . $i . ': <input type="file" name="bestand[]" /><br />';
}
}
echo '<input type="submit" name="submit" value="upload" />';
echo '</form>';
}
else {
for($i = 0; $i < count($_FILES['bestand']['name']); $i++) {
if(isset($_FILES['bestand']['name'][$i]) && is_uploaded_file($_FILES['bestand']['tmp_name'][$i])) {
if (!in_array($_FILES['bestand']['type'][$i], $types)) {
echo 'dit bestandsformaat is niet toegestaan!<br />';
}
else {
if(!move_uploaded_file($_FILES['bestand']['tmp_name'][$i], $map.$_FILES['bestand']['name'][$i])) {
echo 'mislukt!<br />';
}
else { echo 'gelukt!<br />'; }
}
}
}
}
?>
</body>
</html>
<html>
<head>
<title>test form</title>
</head>
<body>
<?php
/**
* map waar de uploads geplaatst worden (!chmod 0777!)
*/
$map = './uploads/' ;
/**
* array met de toegestane upload types
*/
'image/gif' ,
'image/jpeg' ,
'image/png' ,
'image/bmp'
) ;
/**
* aantal bestanden te uploaden:
* default = 5
* verhogen of verlagen varvang dan de 5
*/
$aantal = ( empty ( $_POST [ 'aantal' ] ) ) ?
5 : $_POST [ 'aantal' ] ;
echo '<form name="aantal" action="" method="POST">' ; echo 'aantal bestanden: <input type="text" name="aantal" size="3" maxlength="3" />' ; echo '<input type="submit" name="apply" value="toepassen" />' ; echo '</form><hr /><br />' ;
if ( ! isset ( $_POST [ 'submit' ] ) ) { echo '<form name="upload" action="upload.php" enctype="multipart/form-data" method="POST">' ; for ( $i = 1 ; $i <= $aantal ; $i ++ ) {
if ( $i < 10 ) {
echo 'Bestand 00' . $i . ': <input type="file" name="bestand[]" /><br />' ; }
else if ( $i < 100 && $i >= 10 ) {
echo 'Bestand 0' . $i . ': <input type="file" name="bestand[]" /><br />' ; }
else {
echo 'Bestand ' . $i . ': <input type="file" name="bestand[]" /><br />' ; }
}
echo '<input type="submit" name="submit" value="upload" />' ; }
else {
for ( $i = 0 ; $i < count ( $_FILES [ 'bestand' ] [ 'name' ] ) ; $i ++ ) { if ( ! in_array ( $_FILES [ 'bestand' ] [ 'type' ] [ $i ] , $types ) ) { echo 'dit bestandsformaat is niet toegestaan!<br />' ; }
else {
if ( ! move_uploaded_file ( $_FILES [ 'bestand' ] [ 'tmp_name' ] [ $i ] , $map . $_FILES [ 'bestand' ] [ 'name' ] [ $i ] ) ) { }
else { echo 'gelukt!<br />' ; } }
}
}
}
?>
</body>
</html>
voorbeeld: http://tim.fusionmedia.nl/upload.php /
upload dir: http://tim.fusionmedia.nl/uploads /
Gesponsorde links
Dit onderwerp is gesloten .