Hello,
I've created a code where I simply upload multiple images.
But I am not able to enter the values of the urls 'im/pd/'. $file_name_new;
of the variable $file_destination
in the DB.
In DB I have ..
User_id | img1 | img2 |
What should I include in the code so that urls
is inserted in the Database and also how to save the images in the folder.
Code:
//images function
$ads_file = mysqli_real_escape_string($con, sanitize($_FILES['img_file']['name'][0]));
if(!empty($ads_file)) {
$files = $_FILES['img_file'];
$allowed = array('png', 'jpg', 'jpeg', 'gif');
foreach($files['name'] as $position => $file_name) {
$file_tmp = $files['tmp_name'][$position];
$file_size = $files['size'][$position];
$file_error = $files['error'][$position];
$file_ext = explode('.', $file_name);
$file_ext = strtolower(end($file_ext));
if(in_array($file_ext, $allowed)) {
if($file_error === 0) {
if($file_size <= 4097152) {
$file_name_new = uniqid('', true) . '.' . $file_ext;
$file_destination = 'im/pd/'. $file_name_new;
$uploaded[$position] = $file_destination;
//define o caminho para o folder e para DB
} else {
$errors[] = "
<div class='alert warning'>
<span class='closebtn'>×</span>
<strong><i class='fas fa-file-excel'></i></strong> Esta imagem é demasiado grande.
</div>";
}
} else {
$errors[] = "
<div class='alert warning'>
<span class='closebtn'>×</span>
<strong><i class='fas fa-plug'></i></strong> Falha ao efetuar o upload. Tente novamente...
</div>";
}
} else {
$errors[] = "
<div class='alert warning'>
<span class='closebtn'>×</span>
<strong><i class='fas fa-file-excel'></i></strong> Ficheiro desconhecido, tente outro.
</div>";
}
}
}
New Error
I used the variables you gave me in relation to
$praBanco .=" '".$file_destination."', ";
for ($x = 1; $x <=$quantColunas; $x++) {
$colunas.=" ads_image_".$x." = ";
}
$praBanco = substr($praBanco,0,-1);
$colunas = substr($colunas,0,-1);
$ columns and $ bank
The problem is that ... It does not update because I think something is wrong regarding the entry in the update.
$smtp_process = "UPDATE public_ads SET ads_title = '$ads_title', ads_content = '$ads_content', ads_price = '$ads_price', edit_attempts = edit_attempts + 1, $colunas = '$praBanco' WHERE ads_id = '$editor_id'";
$smtp_request_query = $con->query($smtp_process);
But ... it does not update nor show errors ...
I think about this: $ columns = '$ bank'
The goal is for it to add in the Database the path of the number of uploaded images. As done in INSERT, now UPLOAD.