I have a problem with my multiple file uploading script.
Here's my code :
Admin.php:
<form method="post" action="upload.php" enctype="multipart/form-data">
<input multiple="multiple" type="file" name="file[]">
<input type="submit" name="send" value="Envoyer Images">
</form>
Upload.php:
<?php
session_start();
$message = '';
$extensions = array('.png', '.jpg', '.jpeg', '.JPG', '.PNG', '.JPEG');
try{
$db = new PDO('mysql:host=localhost;dbname=db', 'root', '');
}
catch(Exception $e){
die('Erreur : ' . $e->getMessage());
}
$query = $db->prepare('SELECT max(id) as id FROM t_picture');
$query->execute();
$data = $query->fetch();
$i = $data['id'] == NULL ? 0 : $data['id'];
echo 'i = ' . $i;
if(isset($_FILES['file'])){
$dossier = 'pictures/';
$message = '#1 Reached';
foreach ($_FILES['file']['tmp_name'] as $index => $tmpName){
$message = '#2 Reached';
if(!empty($_FILES['file']['error'][$index])){
$message = 'There is an error #2';
break;
}
$ext = strrchr($_FILES['file']['name'][$index], '.');
$tmp_name = strval($i) . $ext;
echo 'Name : ' . $tmp_name;
if(!empty($tmpName) && is_uploaded_file($tmpName) && in_array(strrchr($tmp_name, '.'), $extensions)){
echo '#4 Reached';
move_uploaded_file($tmpName, $dossier . $tmp_name);
$i++;
$message += '<p>Index '. strval($i) .' uploaded !</p>';
}
}
}
else{
$message ='Is not set';
}
echo $message;
The thing is, I can upload one or multiple files, it works according to the files i'm uploading.
When the problem occured, i think that's because i'm bursting a 2M limit but i've changed the max_file_size value in my php.ini, and my phpinfo() correctly indicate 64000M (Test value).
So when it desn't work, i have an Undifined Index for each call to $_FILES['file'].. Do you know what's wrong?
Have you checked? in your php.ini
upload_max_filesize "64M" //thats OK
post_max_size "??M" //??
max_file_uploads ?? //how many files?
post max size must be larger than upload max file size. also you have enctype to multipart/form-data in the form tag which is good.