0
Good afternoon, I’m trying to make the file upload function via PHP using the code below:
if(isset($_FILES['arquivo']))
{
$diretorio = "D:/wamp64/www/revi/arquivos/postagens/".$postagem;
if(!is_dir($diretorio))
{
mkdir("D:/wamp64/www/revi/arquivos/postagens/".$postagem , 0777);
$arquivo = $_FILES['arquivo'];
for ($k = 0; $k < count($arquivo['name']); $k++)
{
$destino = $diretorio."/".$arquivo['name'][$k];
if (move_uploaded_file($arquivo['tmp_name'][$k], $diretorio))
{
echo "MOVEUUUUUU<br>";
}
else
{
echo "não moveu! <br>";
echo $_FILES["arquivo"]["error"];
}
}
}
And my form is like this
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="arquivos[]" multiple/>
<button type="submit">Upload</button>
</form>
But it just doesn’t work. Echo’s $FILES["arquivo"]["error"]
returns 0 as if you had successfully uploaded, but I go in the folder and there is nothing there. What is missing to work?
Thank you!
happens the "MOVEUU<br>"?
– Miguel
Does not happen. It shows the "Did not move" and the number 0 on the bottom line.
– WitnessTruth
The folder it creates with all permissions OK, but without any file inside. As I can see this log?
– WitnessTruth
One more remark: whenever you do multiple paths, note the 3rd parameter, the recursive in mkdir("D:/wamp64/www/revi/files/posts/".$post , 0777); - and note that the 2nd parameter is ignored in Windows. And check the value of $posts to see if the folder is right.
– Bacco
I made some changes here and is giving the following error: move_uploaded_file(): The Second argument to copy() Function cannot be a directory
– WitnessTruth
You missed the variable inside
(move_uploaded_file($arquivo['tmp_name'][$k], $diretorio)
, the correct one would be, $destino);
, see the answer.– Guilherme Nascimento