Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

move_uploaded_file failed to open stream and Permission denied error

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 ?

like image 806
user2988966 Avatar asked Dec 07 '22 04:12

user2988966


1 Answers

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.

like image 158
Artas Avatar answered May 02 '23 13:05

Artas