Help with post upload and move file manipulation in PHP

Asked

Viewed 183 times

1

After uploading the file, and sending the form information to PHP page, I receive the file with $_FILES['MyFile']. After receiving the file, I move it to another folder of my system: if (move_uploaded_file($_FILES['MyFile']['tmp_name'], $uploaddir.basename($_FILES['MyFile']['name'])){ ...

My problem is. After moving this file to a new directory, I cannot read it in the new directory. To illustrate I’ll leave a part of the code here:

$fil = $_FILES['file-intimacao'];
$uploaddir = 'files/';
$files = '';

if(move_uploaded_file($fil['tmp_name'], $uploaddir.basename($fil['name']))){
    $files = $uploaddir.$fil['name']; // novo diretório do arquivo
    $teste = file_exists ( $files ); //$teste me retorna falso, não me deixando utilizar o arquivo.
}
  • 1

    the directory has read permissions?

  • 1

    Have you checked the directory files is with reading and writing permission?

  • Excuse the ignorance, but if it is described in properties of the folder, this "read only". But I can’t get this"

  • @Kazzkiq ? Miguel Borges ?

  • As you are trying to move a file to this folder through PHP, it needs to have "write" enabled as well, otherwise the operating system will bar the server action. To change this option you need to be computer administrator.

2 answers

4


Try to do it this way:

$fil = $_FILES;
$uploaddir = 'files/';
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$destino = $uploaddir.$fil['name'];

if(move_uploaded_file($fil['tmp_name'], $destino)){            
    $teste = file_exists ( $destino ); 
}

Also check if the files folder exists and you have write permission.

0

Browser other questions tagged

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