I have to upload 2 images. One is a product image and another is a QR. Also the code I want to insert in a MySQL database the URL of each image. I managed to get the URL of each image registered in the database and upload one of the two images, but the image that corresponds to the QR code is not only the first server, I do not receive any error message.
This is the table in MySql The product image is "product_image" and that of the QR code is product_qr
This is the user "interface" created with "modal" in PHP- Then I put the piece of code that corresponds to the function that connects to the database and that is responsible for uploading the files:
$type = explode('.', $_FILES['productImage']['name']);
$type = $type[count($type)-1];
$typeQR = explode('.', $_FILES['productQR']['name']);
$typeQR = $typeQR[count($typeQR)-1];
$url = '../assests/images/stock/'.uniqid(rand()).'.'.$type;
$urlQR = '../assests/images/stock/'.uniqid(rand()).'.'.$typeQR;
if(in_array($type, array('gif', 'jpg', 'jpeg', 'png', 'JPG', 'GIF', 'JPEG', 'PNG')) ||
in_array($typeQR, array('gif', 'jpg', 'jpeg', 'png', 'JPG', 'GIF', 'JPEG', 'PNG')) ) {
if(is_uploaded_file($_FILES['productImage']['tmp_name']) ||
is_uploaded_file($_FILES['productQR']['tmp_name']) ) {
if(move_uploaded_file($_FILES['productImage']['tmp_name'], $url) ||
move_uploaded_file($_FILES['productQR']['tmp_name'], $urlQR)) {
$sql = "INSERT INTO product (product_name, product_image, brand_id, categories_id, quantity,
rate, active, status, description, position_store, status_product, reference, product_qr)
VALUES ('$productName', '$url', '$brandName', '$categoryName', '$quantity', '$rate',
'$productStatus', 1, '$productDescription', '$positionStore', '$statusObject', '$reference', '$urlQR')";
This is the "modal" code:
<div class="modal-body" style="max-height:450px; overflow:auto;">
<div id="add-product-messages"></div>
<div class="form-group">
<label for="productImage" class="col-sm-3 control-label">Imagen: </label>
<label class="col-sm-1 control-label">: </label>
<div class="col-sm-8">
<!-- the avatar markup -->
<div id="kv-avatar-errors-1" class="center-block" style="display:none;"></div>
<div class="kv-avatar center-block">
<input type="file" class="form-control" id="productImage" placeholder="Imagen del producto" name="productImage" class="file-loading" style="width:auto;"/>
</div>
</div>
</div>
<div class="form-group">
<label for="productQR" class="col-sm-3 control-label">QR: </label>
<label class="col-sm-1 control-label">: </label>
<div class="col-sm-8">
<!-- the avatar markup -->
<div id="kv-avatar-errors-1" class="center-block" style="display:none;"></div>
<div class="kv-avatar center-block">
<input type="file" class="form-control" id="productQR" placeholder="Imagen QR" name="productQR" class="file-loading" style="width:auto;"/>
</div>
</div>
</div>
Y>
As I say, everything works fine, because the QR image does not upload to the server.