Upload Out of Place

Asked

Viewed 31 times

-4

inserir a descrição da imagem aqui

Well I’m a little confused here because I’m creating the folder but at the time of lifting it Upa a level up. where is the error ?

 if (is_uploaded_file($_FILES["foto"]["tmp_name"])) {
mkdir("../img/$Npasta") or die("erro ao criar diretório $Npasta");
$foto = time() . '_' . $_FILES["foto"]["name"];
$diretorio = '../img/$Npasta';
$dirfoto = $diretorio.$foto;

if (!move_uploaded_file($_FILES["foto"]["tmp_name"], $dirfoto)) {
  $error = TRUE;
 }
}

Addendum: I am creating the dynamic folders taking the last id of the bank adding + 1 and the folder is being created, only not understanding is pq at the time of raising the variable seems to be "lost" because as you see the name is $Npasta.taltaltaltaltal.jpg where it actually would have to be img/4/filename.jpg

  • Paste the normal code here... because that way you can’t even read the code

  • If clicking on the image will increase, I put image pq to see the server and how it is being uploaded

1 answer

1


You can do so too:

if(is_uploaded_file($_FILES["foto"]["tmp_name"])) {
    mkdir("../img/".$Npasta) or die("erro ao criar diretório $Npasta");
        $foto = time() . "_" . $_FILES["foto"]["name"];
        $diretorio = "../img/".$Npasta."/";
        $dirfoto = $diretorio.$foto;

    if (!move_uploaded_file($_FILES["foto"]["tmp_name"], $dirfoto)) {
        $error = TRUE;
        echo "Imagem não enviada!";
    }
}
  • in this case I am taking the image via post, and I am also using a domain for creation I believe that defining the directory so it can cause some future problem, because if one day you solve change it to the right root I will have to change. Anyway it worked creation of the directory , however the image went to the folder level above

  • It worked out Andre, more here explains me there normal pq $Npasta was not picking up and ". $Npasta." so it picks up?

  • You need to concactenate the variables, when Voce will use only with '', Voce can use {$var} the keys replace the ''

Browser other questions tagged

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