j'ai un formulaire dans lequel j'avais jusqu'a present 1 seule image a uploader.
aucun probleme.
maintenant je voudrais faire en sorte que mon script puisse gerer entre 1 et 6 photos a uploader.
je ne vois pas trop comment faire.
est ce que qqun pourrait me dire quelle est la meilleure marche a suivre. j'essayerais de me debrouiller pour le code
merci
$uploaddir = "../../gifts/";
$allowed_ext = array( 'jpg', 'gif', 'jpeg', 'png' );
$max_size = "50000";
$max_height = "300";
$max_width = "300";
$upload = '';
//get the file's extension
$ext = pathinfo($_FILES['file']['name']);
$extension = $ext['extension'];
//compare uploaded file with authorized extensions
if (in_array($extension,$allowed_ext))
{
//check the file's size in kb
if($_FILES['file']['size'] > $max_size)
{
print "File size is too big!";
$upload = false;
}
//check the file's dimension WxH
if ($max_width && $max_height)
{
list($width, $height, $type, $w) = getimagesize($_FILES['file']['tmp_name']);
if($width > $max_width || $height > $max_height)
{
print "<br>File height and/or width are too big!";
$upload = false;
}
//upload the file!
else
{
if(empty($upload) && is_uploaded_file($_FILES['file']['tmp_name']))
{
//create a random name for the uploaded file
$name = random_string();
$uploadname = "$name.$extension";
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$uploadname);
//insert fom values into database
$fields = array_keys($_POST);
for ($i = 0; $i < count($fields); $i++)
{
$array = array($_POST[$fields[2]], $_POST[$fields[1]], $_POST[$fields[0]]);
$start = implode("-", $array);
$array = array($_POST[$fields[5]], $_POST[$fields[4]], $_POST[$fields[3]]);
$expiry = implode("-", $array);
$name = addslashes($_POST[$fields[6]]);
$description = addslashes($_POST[$fields[7]]);
$stock = $_POST[$fields[8]];
$points_redeem = $_POST[$fields[9]];
$points_play = $_POST[$fields[10]];
$type = $_POST[$fields[11]];
$link = $_POST[$fields[12]];
}
$query= ("INSERT INTO gifts (start, expiry, name, description, stock, points_redeem, points_play, type, link, pic_path)
VALUES ('$start', '$expiry', '$name', '$description', '$stock', '$points_redeem', '$points_play', '$type', '$link', 'gifts/$uploadname')");
mysql_query($query) or die('Invalid query: ' . mysql_error());
print "Your file has been uploaded successfully! Yay!";
}
else
{
print "<br>failed uploading the file";
}
}
}
}
else
{
print "Incorrect file extension!";
}