Help with manipulation after upload and move file in PHP

1

After uploading the file, and sending form information to PHP page, I get the file with $_FILES['MyFile'] . After receiving the file, I move it to another folder on 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 can not read it in the new directory. For example 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.
}
    
asked by anonymous 03.07.2014 / 20:49

2 answers

4

Try to do this:

$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 that the files folder exists and has write permission.

    
03.07.2014 / 21:44
0

Check the permissions of the directory. If the environment is Linux, you can use the PHP chmod () command after the transfer:

More info: link

    
03.07.2014 / 21:25