Change the directory where the folder will be created

Asked

Viewed 320 times

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.

  • You can put an example?

  • Yes, I can. Hold on, I have already put, I am without machine ! Rs

  • 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

1 answer

0


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

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

or

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

Probably putting 1 of these 3 will solve:

wordpress/wp-content/themes/busiprof/img

wordpress/wp-content/themes/busiprof/img

wp-content/themes/busiprof/img

This is because it will depend on where the PHP file is. If you don’t solve put your website name in front or use a variable GLOBAL of PHP:

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

About the problem of Android I would need to see the HTML form, it may be that it is not really going up the file.

  • But it refers to both the folder creation path and the folder display path?

  • The display, since this is the problem you presented in doubt. ’s paths as paths htdocs, www, html are only to point files to server, pro client the path is remote, starting by HTTPS or HTTP, which are precisely the virtualization of the folder where you can insert your PHP and HTML scripts.

  • I noticed, thank you for the explanation and it was with your answer that I arrived at the solution. But now I have another problem that I added in the question above. If you upload it by windows, it works fine, but if you upload it by camera via Android I can’t display the image

  • About the problem of Android I would need to see the HTML form, it may be that it is not really going up the file.

  • Look at this question with this form link I make the images by update where you have the query that I show to the user of the maintenance request and then create three fields (Image, Treatment and Status) for it to insert in the same order line to give as completed service

  • But the extension is the same as in windows jpg and png, but in this case it gives the error as not found from the image

  • See for your manager FTP if the image is actually being read and recorded, if the image is broken it is because your form may be using the wrong method. I edited the answer to show how to put the HTTP protocol with the site name in the image path. If it doesn’t work I’ll explain how to upload a file in BASE64, that is, at first will do by HTML5 (Canvas) then yes send to the contents of the converted file.

  • Not solved the problem, with Android does not show the image

  • But the image is broken in FTP?

  • As I see it, if it’s broken?

  • The image exists in the folder viewing by FTP, if yes download to your machine and if the image does not appear by the viewer is why its contents did not rise, only the file was created empty.

  • at the top I edited the question to show the form I asked, I put all the steps I do until the visualization. But the upload is well done, because I go inside the folder in the directory and it opens.

  • So if the image appears try the following, hold the tap on your Android screen on the image that does not appear, when the menu appears select to display the image, see exactly the URL that is appearing and compare with that of the browser. I have two ideas of possible mistakes, and if it doesn’t work we’ll have to appeal to BASE64, which unfortunately won’t work on Androids before 4.4 either.

  • I when I display the image is not on android, I on android upload but then I can not see them on a windows pc, but if you both upload and preview in windows works properly. With this image I uploaded in windows and preview in windows and works properly and this is the way http://xxx.xxx.x.xx/wordpress/img/1.png. this I uploaded on android and does not display the path is http://xxx.xxx.x.xx/wordpress/img/IMG_20180221_113653.jpg, diz was not found on this server.

  • I already solved the problem, I had this path $tabela1 .= '<td><<img src="../img/' .$rows_cursos['Imagem']. '"/></td>'; and the solution is to put this way $tabela1 .= '<td><<img src="/wordpress/wp-content/themes/busiprof/img/' .$rows_cursos['Imagem']. '"/></td>';

Show 10 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.