-1
I’m learning to use a server cloud and I’m having trouble uploading files.
I made a code with simple PHP and HTML:
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="img" />
<input type="text" name="titu" placeholder="Titulo" />
<input class="lal" type="submit" name="cadastrar" value="Cadastrar" >
</form>
<?php
require_once 'conexao.php';
if(isset($_POST['cadastrar'])){
/* IMAGEM */
$img = $_FILES['img'];
$name = $img ['name'];
$tmp = $img ['tmp_name'];
$size = $img ['size'];
$ext = end(explode('.',$name));
$pasta = "../imagem/";
$maxSize = 1024 * 1024;
$permiti = array('jpg', 'jpeg', 'png');
$titu = filter_input(INPUT_POST, 'titu');
if(empty($titu)){echo "Informe um titulo";
}else{
$name = uniqid().'.'.$ext;
try{
$stmte = $pdo->prepare("INSERT INTO post(TITULO, IMAGEM) VALUES (:1, :2)");
$stmte->bindParam(":1", $titu , PDO::PARAM_STR);
$stmte->bindParam(":2", $name , PDO::PARAM_STR);
$executa = $stmte->execute();
if($executa){
echo 'Dados inseridos com Sucesso';
$upload = move_uploaded_file($tmp, $pasta.$name);
}
else{
echo 'Erro ao inserir os dados';
}
}
catch(PDOException $e){
echo $e->getMessage();
}}}
?>
And the comic book record is going perfectly, so much so that I can get into phpMyAdmin and see there the newly added record as well as updating the home page where the posts are displayed.
But as you can see, I’m uploading an image file but, although the record is being successfully inserted into the BD, the move_uploaded_file
does not move the temporary file as it should.
And that’s my problem because I have to display the post with the image, but as this is not being sent, it does not exist.
I don’t understand why, since if I run the code on my PC, with WAMP, both the registration and the upload work normally. And the server appears to work, since it does not return any error message, but the upload is not performed.
I don’t think it’s any wrong code because I’ve used that same code several times on shared servers and it’s always worked. The problem is only on this server cloud.
I believe that the problem may lie in the very configuration of cloud, because I’ve even changed the folder’s permission images for 777 and nothing.
I also changed some PHP.INI directives as shown in the image below:
Would anyone know the cause?
They are not the same. The one on my pc is Windows. The one on the server is linux Ubuntu 10.04
– ivan veloso
avoid using <code>'</code> or <code>/</code> where you refer to?
– ivan veloso
is yes @lost, I thought it had worked, but not working no. It was just my illusion. However now the problem is clearer. Take a look at the bars? what bars?
– ivan veloso
But @lost switch the bars in case they are wrong will help me in what? Because in the case when I run the code by serve it does not even register in the BD, now register locally it enters the information in the BD, but does not transfer the image and/or video pro serve
– ivan veloso
Let’s go continue this discussion in chat.
– rray
So it gets hard, you’re changing the question completely, including stuff I put in the answer. And the worst, the most important things I’ve posted, which are the right paths, it seems to me you haven’t used. PS: I think it’s good for the person to start with the simplest possible and get better with each step until they get into trouble, just don’t think it’s cool to change everything after it’s posted. Anyway, if it’s to test, I would suggest starting from scratch and testing the connection with DB even before having FORM. Then do the FORM without UPLOAD, and then put the UPLOAD.
– Bacco
The question still has the same basis. the code is registering everything in the database of the serve but it is not transferring the media files. My difficulty is not in registering things in BD but transferring the files to the server. This code I added is the same as before, but much simpler, only with the necessary, this is a test to see if I can download pro serves at least one image! only I’m not even getting it.
– ivan veloso
Ivan, is that when you enter into the question information that was in one of the answers, you invalidate the answer at least partially.
– bfavaretto
@Bacco already did it. I’ve dissected the whole code. I have tested the connection, the tables, the posting code without the upload and all these tests gave 100%, there was no error. But the problem is only in sending media to the server. Because now I’m uploading and is even registering, but the image I select does not go to folder.
– ivan veloso
Guys, I rephrased the question. If you could reopen it, I’d appreciate it!
– ivan veloso
I had a good improvement in the newsroom, let’s see if it helps.
– Bruno Augusto