I've been trying to upload multiple files, I have looke dmany examples, I believe I'm following all the recommendations, still cannot make it work. It works for a single file, but the code errors when I try multiple files. Here´s my html:
<form id="NewImages" method="POST" action="../cgi-bin/saveImages.php?action=add">
<section id="ActionsBar" class ="actions-bar">
<div class="files-upload">
<input id="SelectFiles" name="selectfiles[]" type="file" accept="image/*" onchange="previewAll(this)" multiple>
<label id="FilesLabel" class="form-label">Solo se permiten archivos tipo imagen (jpg|png|bmp|gif)</label>
</div>
<div style="display:inline-block; vertcial-align:top;">
<button id="UploadButton" name="uploadbutton" class="side-button" type="button" onclick="document.getElementById('Add').click()" disabled>Agregar Imagenes</button>
</div>
</section>
<section id="Preview" class="flex-box">
<input id="Add" type="submit" style="display:none;">
<!-- div id="Loader" class="inner-box">-->
<div id="pBox-0" class="service-box">
<figure id="pFigure-0">
<img id="pImage-0" src="../images/icon-house.png" alt="AGR Bienes Raices compra, venta y renta de casas en Querétaro">
</figure>
<span id="pFile-0" class="file-name">*Nombre del archivo*</span>
<div id="pDiv-0">
<div id="pDivInp1-0" class="div-input"><label id="pLabel1-0" class="form-label" for="pFrontPage-0">Mostrar en <abbr id="pAbbr1-0" title="Mostrar en pagina de bienvenida de AGR bienes raices">portada </abbr></label> <input id="pFrontPage-0" type="checkbox" class="form-input"></div>
<div id="pDivInp2-0" class="div-input"><label id="pLabel2-0" class="form-label" for="pShowPicture-0">Mostrar en <abbr id="pAbbr2-0" title="Mostrar imágen en el catálogo de AGR bienes raices">catalogo </abbr></label> <input id="pShowPicture-0" type="checkbox" class="form-input"></div>
<input id="pOrder-0" type="text" class="form-input-text" placeholder="1,2,3,..">
<input id="pExclude-0" type="button" class="no-button" value="Excluir" onclick="excludeBox(0)">
</div>
</div>
<!-- /div>-->
</section>
</form>
Forms calls for a program called saveImages.php. This code is here:
<?php
session_start();
try{
$action=$_GET["action"];
include '/home/k3mq6hsrski5/agr/php/loadImage.php';
$logfile= '/home/k3mq6hsrski5/public_html/users/logs/user-' . date("Y-m-d") . '.log';
file_put_contents($logfile, date("H:i:s") . "*-- saveImage.php started --*\r\n", FILE_APPEND);
$err ="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if($action == "add"){
$vFile = basename($_FILES["selectfiles"]["name"][0]);
file_put_contents($logfile, date("H:i:s") . "-- Location:" . $_SESSION["location"] . ", Section:" . $_SESSION["section"] . ", file:$vFile\r\n", FILE_APPEND);
$nFiles= count($_FILES['selectfiles']['name']);
file_put_contents($logfile, date("H:i:s") . "-- Files to read:$nFiles --\r\n", FILE_APPEND);
for ($i = 0; $i < $nFiles; $i++) {
$vFile = basename($_FILES["selectfiles"]["name"][$i]);
file_put_contents($logfile, date("H:i:s") . "-- Processing file:$vFile --\r\n", FILE_APPEND);
if (uploadImg('selectfiles',$vFile,true,$i)!=true){
$err .= $_SESSION["err"];
}
}
header("Location: ../actions/images.php?asset=" . $_SESSION['currasset']);
}elseif ($action == "save"){
header("Location: ../actions/catalogue.php");
}else{
header("Location: ../actions/images.php?asset=" . $_SESSION['currasset']);
}
}
}catch (Exception $e){
$_SESSION["err"]= "Program saveImages.php failed and threw an excpetion.";
$_SESSION["log"]= $e->getMessage();
header("Location: ../actions/userAck.php?target=/actions/images");
}
?>
It seems the variable $_FILES is not working at all, try{} catch{} not working either.
If somebody can help me to find my error, Thanks