4

i'm trying to upload a file but i'm getting this following errors in my browser:

Warning  move_uploaded_file(public/upload/udesignwptheme138.zip) [function.move-uploaded-file]: failed to open stream: Permission denied in <b>/home/monivbr/public_html/classes/system/Util.php on line 1803

Warning:  move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpJtBlbi' to 'public/upload/udesignwptheme138.zip' in /home/monivbr/public_html/classes/system/Util.php on line 1803

this is my php class that make uploads to my server:

            foreach ($files as $file)
            if($file['tmp_name'] != "" && $file['error'] != 4){

                if($file['size'] < 10000000000){
                    $nome_antigo = $file["name"];
                    $novo_nome = strtolower(preg_replace("/[^a-zA-Z0-9_.]/", "", strtr($nome_antigo, "áàãâéêíóôõúüçÁÀÃÂÉÊÍÓÔÕÚÜÇ ", "aaaaeeiooouucAAAAEEIOOOUUC_")));


                    $query = $conexao->prepare('SELECT MAX(id) AS maxId FROM tbArquivo');
                    $query->execute();
                    $arquivo = $query->fetchObject();   

                    $caminhoArquivo = 'public/upload/';
                    $nomeArquivo = substr($novo_nome, 0, strripos($novo_nome, '.')).$arquivo->maxId;
                    if($idTipoArquivo == '6'){ //6 = arquivos xml de tradução
                        $caminhoArquivo  = 'public/traducao/';
                        $nomeArquivo = substr($novo_nome, 0, strripos($novo_nome, '.'));
                    }

                    $extensao = substr($novo_nome, strripos($novo_nome, '.'));

This line below is where is located the error:

move_uploaded_file($file["tmp_name"],$caminhoArquivo.$nomeArquivo.$extensao);




                    $query = $conexao->prepare("INSERT INTO tbArquivo
                                                (idTipoArquivo, idComplementar, idComplementar2, nomeArquivo, caminhoArquivo, tamanhoArquivo, extencaoArquivo, excluido)
                                                VALUES
                                                (:idTipoArquivo, :idComplementar, :idComplementar2, :nomeArquivo, :caminhoArquivo, :tamanhoArquivo, :extencaoArquivo, 0)");
                    $query->bindParam(":idTipoArquivo", $idTipoArquivo);
                    $query->bindParam(":idComplementar", $idComplementar);
                    $query->bindParam(":idComplementar2", $idComplementar2);
                    $query->bindParam(":nomeArquivo", $nomeArquivo);                
                    $query->bindParam(":caminhoArquivo", $caminhoArquivo);
                    $query->bindParam(":tamanhoArquivo", $file['size']);
                    $query->bindParam(":extencaoArquivo", $extensao);

                    $query->execute();

                }
            }   

this is my .htaccess file:

php_value upload_max_filesize 30M
php_value post_max_size 30M
php_value max_input_time 6000000
php_value max_execution_time 6000000
php_value memory_limit 35M

this is the var_dump of the variables:

var_dump($extensao);
var_dump($file["tmp_name"]);
var_dump($caminhoArquivo);
var_dump($nomeArquivo);

string(4) ".zip" string(14) "/tmp/phpKUpN24" string(14) "public/upload/" string(17) "udesignwptheme139" 

someone knows what culd be wrong ?

user2988966
  • 45
  • 1
  • 1
  • 4
  • 1
    Your problem is defined in warning. Your web server running process do not have write permission to the folder where your trying to move the uploaded file. – chanchal118 Dec 14 '13 at 11:14
  • chanchal, tanks for responding... but i believe that the permission is not the problem becouse when i try to upload small files i'm having success in the upload... – user2988966 Dec 14 '13 at 11:19
  • Can you print the file info array? What is the size of the file? – chanchal118 Dec 14 '13 at 11:21
  • the permission of the upload folder is 755, and the public folder is 755 to – user2988966 Dec 14 '13 at 11:23
  • the file size is 10 mb – user2988966 Dec 14 '13 at 11:23
  • possible duplicate of [move\_uploaded\_file gives "failed to open stream: Permission denied " error after all configurations i did](http://stackoverflow.com/questions/8103860/move-uploaded-file-gives-failed-to-open-stream-permission-denied-error-after) – Matt Clark Feb 14 '15 at 08:11

3 Answers3

15

Maybe you can consider changing the upload folder chmod 755 or 777

chmod 777 folder_path 

By this we are setting read. write and execute privilege for owner, group as well as others.

Foreever
  • 7,099
  • 8
  • 53
  • 55
Artas
  • 262
  • 2
  • 6
  • 2
    I'm getting this same error, however my permissions are already 755 or higher and everything is owned by the same user. – limeandcoconut Feb 08 '15 at 19:02
  • 1
    @BrassApparatus the uploads folder needs to have write permission which is 6. So your permissions need to be 765 or higher. explanation here - http://www.elated.com/articles/understanding-permissions/. I know this is an old comment but for anyone else who might have that issue. – Craicerjack Sep 22 '15 at 09:19
  • 1
    I did eventually fix it. +1 @Craicerjack for commenting what I should have for posterity. – limeandcoconut Sep 22 '15 at 12:38
  • 1
    Adding 777 chmod is VERY risky and definitely wrong. Please consider learning how permissions work. – Kirill Titov Mar 21 '16 at 09:51
0

Its because of the you dont have the sufficient permission on the Folder. Change this permission to read and write. That's all !

Ravindra Miyani
  • 360
  • 6
  • 14
0

Do not change the folder path

chmod -R 777 /home/monivbr/public_html/classes/system/Util.php
Shabeer K
  • 1,489
  • 16
  • 23