0
I do this way the upload where creates the folder inside the wordpress folder:
if (!file_exists($pasta)){
mkdir("$pasta", 0777);
}
$diretorio = "img/";
foreach ($registro as $Id => $estado) {
$url = $diretorio . $_FILES['Imagem']['name'][$Id];
$nome_arquivo = $_FILES['Imagem']['name'][$Id];
// salva as imagens na pasta
move_uploaded_file($_FILES['Imagem']['tmp_name'][$Id], $url);
Change the path to creating the folder inside the theme folder:
$pasta = "/var/www/html/wordpress/wp-content/themes/busiprof/img";
if (!file_exists($pasta)){
mkdir("$pasta", 0777);
}
$diretorio = "/var/www/html/wordpress/wp-content/themes/busiprof/img/";
foreach ($registro as $Id => $estado) {
$url = $diretorio . $_FILES['Imagem']['name'][$Id];
$nome_arquivo = $_FILES['Imagem']['name'][$Id];
// salva as imagens na pasta
move_uploaded_file($_FILES['Imagem']['tmp_name'][$Id], $url);
Now to display the images in the table I do so but does not display the images:
$result_cursos = "SELECT
Funcionario,
Imagem
FROM centrodb.RegistoManutencao LEFT OUTER JOIN centrodb.InfoLuvas
ON centrodb.InfoLuvas.Id = centrodb.RegistoManutencao.Colaborador
WHERE Estado IS NULL OR Estado <> 'Concluído';";
$resultado_cursos = mysqli_query($conn, $result_cursos);
$tabela1 .= '<div style="float: center" table align="center">';
$tabela1 .= '<table border="5">';
$tabela1 .= '<tr>';
$tabela1 .='<thead>';
$tabela1 .= '<tr>';
$tabela1 .= '<th>Colaborador</th>';
$tabela1 .= '<th>Imagem</th>';
$tabela1 .= '</tr>';
$tabela1 .='</thead>';
$tabela1 .='<tbody>';
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$tabela1 .= '<tr>';
$tabela1 .= '<td>'.$rows_cursos['Funcionario'].'</td>';
$tabela1 .= '<td><img src="/var/www/html/wordpress/wp-content/themes/busiprof/img/' .$rows_cursos['Imagem']. '" /></td>';
$tabela1 .= '</tr>';
}}
$tabela1 .= '</tr>';
$tabela1 .='</tbody>';
$tabela1 .= '</table>';
$tabela1 .= '</div>';
echo $tabela1;
and the result is this as shown in the image:
I solved the problem. The problem is on the way. Solution:
$tabela1 .= '<td><img src="../img/' .$rows_cursos['Imagem']. '" /></td>';
If you upload images by Windows displays the images perfectly in the part of the query, but if you upload the images via Android then I can’t see the images, I get error as shown in the image above. My code is the way I show it in the question But the image I insert for Android gets in the folder img
(upload) and insert the name and extension to the database table. I am inserting images taken by the Android camera
Creation of the image field:
$tabela1 .= '<td> <input type="file" name= "Imagem['.$rows_cursos['Id'].']" id= "Imagem"></td>';
Form for inserting the image:
echo "<form method='POST' action='' enctype='multipart/form-data'>";
echo $tabela1;
echo "<input type='submit' name='registar' value='Registo'>";
echo "</form>";
Update in the table and create the folder:
$pasta = "http://".$_SERVER['SERVER_NAME']."/wp-content/themes/busiprof/img";
if (!file_exists($pasta)){
mkdir("$pasta", 0777);
}
$diretorio = "http://".$_SERVER['SERVER_NAME']."/wp-content/themes/busiprof/img";
foreach ($registro as $Id => $estado) {
$url = $diretorio . $_FILES['Imagem']['name'][$Id];
$nome_arquivo = $_FILES['Imagem']['name'][$Id];
// salva as imagens na pasta
move_uploaded_file($_FILES['Imagem']['tmp_name'][$Id], $url);
$conn->query("UPDATE RegistoManutencao SET Estado = '$registro[$Id]', Imagem = '$nome_arquivo', Tratamento = '$tratamento[$Id]' WHERE Id='".$Id."'");
}
Image display in user query:
$tabela1 .= '<td><<img src="../img/' .$rows_cursos['Imagem']. '" width="600" height="400" alt="CodigoFonte.com.br" onMouseOut="diminui(this)" onMouseOver="aumenta(this)"/></td>';
Inspecting the image shows this error in the console: Failed to load resource: the server responded with a status of 404 (Not Found)
If you have a "config" file with the final variables, constants, create one with this path.
– rbz
You can put an example?
– user104114
Yes, I can. Hold on, I have already put, I am without machine ! Rs
– rbz
This problem already solved of the path, but still without displaying the images in the table where makes the query, I will edit the question
– user104114