Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
843 views
in Technique[技术] by (71.8m points)

php - 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, "áà?aéêíó??úü?áà??éêíó??úü? ", "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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...