I'm trying to do array uploads so that people can upload 5 files at a time, however around the move_uploaded_file() line it fails. Is something obvious wrong??
<?php
if (isset($_POST['submitted'])) {
if ($_POST['terms'] == 'agree' && $_POST['privacy'] == 'agree') {
include ('../includes/thumbnail.php');
$dates = getdate();
$folder = $dates['year'].$dates['mon'].$dates['mday'];
foreach ($_FILES['pictures']['error'] as $key => $error) {
if(isset($_FILES['pictures']['name'])){
if ($error == UPLOAD_ERR_OK){
$extension = explode ('.', $_FILES['pictures']['name']);
$ext = $extension[1];
$random_number = round(mt_rand(1, 1000000));
$new_filename = $folder.$random_number.'.'.$ext;
if(move_uploaded_file($_FILES['pictures']['tmp_name'], "/path/pictures/$new_filename")){
echo 'file uploaded';
echo $folder;
echo $new_filename;
if($ext=='jpg' || $ext=='jpeg' || $ext=='pjpeg'){
thumbjpg('/path/pictures/', '/path/thumbs/', $new_filename, '150');
}elseif($ext=='gif'){
thumbgif('/path/pictures/', '/path/thumbs/', $new_filename, '150');
}else{
$errors[] = 'Wrong filetype, please submit a jp(e)g or gif';
}
$picture = $new_filename;
}else{
$errors[] = 'Error moving file.';
}
}else{
$errors[] = 'Error uploading file.';
}//end error = ok
}//end of filename check
//sql add to database
}//end foreach
//show errors
}else{
echo '<p>You need to agree to the Terms and Conditions and Privacy Agreement.</p>';
}//end terms and conditions
}//end submit
?>
<h1>Upload Pictures To Album : <?=$name;?></h1>
<form action="upload_pictures.php?aid=<?=$aid;?>" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Upload Pictures</legend>
<input type="file" name="pictures[]" />
<br/>
<input type="file" name="pictures[]" />
<br/>
<input type="file" name="pictures[]" />
<br/>
<input type="file" name="pictures[]" />
<br/>
<input type="file" name="pictures[]" />
<br/>
<label for="terms">Agree To <a href="legal/terms.php" target="_blank">T&C</a></label>
<input name="terms" type="checkbox" value="agree" checked/>
<br/>
<label for="privacy">Read Privacy?*</label>
<input name="privacy" type="checkbox" value="agree" checked/>
<br/><br/>
<div align="center">
<input type="submit" name="submit" value="Upload!" />
<input name="reset" type="reset" value="Clear" />
<input type="hidden" name="submitted" value="TRUE" />
</div>
</fieldset>
</form>
<?php
$menu = 'account';
include('../includes/submenu.php');
include ('../includes/footer.php');
?>