Change the directory where the folder will be created

0

I do this the upload where the folder is created 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);

Changing the path to folder creation within 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 this way but do 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 in the way. Solution:

$tabela1 .= '<td><img src="../img/' .$rows_cursos['Imagem']. '" /></td>';

If you upload images from Windows, it displays the images perfectly in the query part, but if I upload the images via Android after I can not see the images, I get the error as shown in the image above. My code is the way I show it in the question But the image I enter for Android is in the img (upload) folder and inserts the name and extension for the database table. I'm inserting images taken by the Android camera

Creating the image field:

$tabela1 .= '<td> <input type="file" name= "Imagem['.$rows_cursos['Id'].']" id= "Imagem"></td>';

Image Insertion Form:

echo "<form method='POST' action='' enctype='multipart/form-data'>";

echo $tabela1;

echo "<input type='submit' name='registar' value='Registo'>";
echo "</form>";

Update to table and folder creation:

$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."'");
} 

Displaying the image in the query for the user:

$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)

    
asked by anonymous 21.02.2018 / 11:09

1 answer

0

You are giving a path that only servidor can directly access:

**/var/www/**html/wordpress/wp-content/themes/busiprof/img

or

**/var/www/html/**wordpress/wp-content/themes/busiprof/img

Probably put 1 of these 3 will solve:

wordpress/wp-content/themes/busiprof/img

wordpress/wp-content/themes/busiprof/img

wp-content/themes/busiprof/img

That's why it will depend on where the PHP file is. If you do not resolve the name of your site in the front or use a% v% of PHP%:

$diretorio = "http://".$_SERVER['SERVER_NAME']."/wp-content/themes/busiprof/img";

On the problem of Android I would need to see the HTML form, it may be that it is not even uploading the file.

    
21.02.2018 / 11:59