0
I am sending an image to a folder and saving only the location (path) of it in the database. If for example the name I assign the image has no accents works perfectly, only when it has accents it doesn’t work. When storing in the database and showing on the website shows everything correct.
When storing in the folder I cannot fetch the respective image because the path (path) is for example "Products/joe" and so the name appears inside the folder z&A
Sending code to the database and folder:
if(isset($_POST['upload']) && isset($_FILES['file-image'])) {
$filetmp = mysqli_real_escape_string($_FILES["file-image"]["tmp_name"]);
$filename = mysqli_real_escape_string($dbc, $_FILES["file-image"]["name"]);
$filetype = mysqli_real_escape_string($dbc, $_FILES["file-image"]["type"]);
$ProdName = mysqli_real_escape_string($dbc, $_POST['nameProduct']);
$ProdPrice = mysqli_real_escape_string($dbc, $_POST['productPrice']);
$ProdDescr = mysqli_real_escape_string($dbc, $_POST['descrProduct']);
$filepath = "Products/" . $ProdName ;
$info = getimagesize($filetmp);
if ($info == FALSE or (empty($ProdName) or empty($ProdPrice) or empty($ProdDescr))) {
alertError();
}elseif ($info == FALSE and (empty($ProdName) or empty($ProdPrice) or empty($ProdDescr))) {
alertError();
}elseif ($info == TRUE and (empty($ProdName) or empty($ProdPrice) or empty($ProdDescr))) {
alertError();
}elseif ($info == TRUE and (!(empty($ProdName) or empty($ProdPrice) or empty($ProdDescr)))) {
move_uploaded_file($filetmp, $filepath);
$result = mysqli_query($dbc, "INSERT INTO images (img_name,img_path,img_type) Values('$ProdName','$filepath','$filetype')") or die(errorAdmin());
$last_id = $dbc->insert_id;
$insertProduct = mysqli_query($dbc, "INSERT INTO products (name_Product,prod_description,prod_price,img_id)
Values('$ProdName','$ProdDescr','$ProdPrice','$last_id')") or die(errorAdmin());
mysqli_query($dbc, "SET NAMES 'utf8'") or die(mysqli_error($dbc));
if ($insertProduct == TRUE and $result == TRUE) {
?>
<script type="text/javascript">
swal({
title: 'Good Job',
text: 'Produto Criado Com Sucesso',
type: 'success',
confirmButtonText: 'Feito'
});
</script>
<?php
}
}
mysqli_close($dbc);
}
You even need the file name to contain accents?
– Amadeu Antunes
Yes because it will be the name of the product, so there may be accented names
– Adriano Maia
I suggest you use the function
mysqli_set_charset(connection, charset)
, whereconnection
is your connection object andcharset
the type of encoding you are using in the bank. Ex.:mysqli_set_charset($conn, 'utf8')
.– rdleal
where do I use this function? and that I already have in the page code the ini_set function()
– Adriano Maia
places in php this function that @Pantera referred to
– Amadeu Antunes
@A.Maia can put right after opening the connection with the bank. Or at the beginning of this your script, as a test.
– rdleal
Thanks for the help but it doesn’t work anyway
– Adriano Maia
@A.Maia accentuation is a bit complicated, especially when it comes to database/language/file system integrations. A common practice in cases such as yours is to "clear" the name with accents, replacing the accents with pure ASCII. Solutions such as that one should help you in this.
– rdleal
@Panther thank you very much, it is then without accents. Thank you for the solution
– Adriano Maia
Normally if you have a product database, you do not need to use the product name in the file. Use base ID instead of name, which simplifies everything.
– Bacco