php文件上传权限?

时间:2012-04-01 06:29:40

标签: php

我使用以下脚本将图片上传到我的网站。它在我的本地机器上完美运行。但当我在我的FTP帐户上运行godady时,它向我显示了权限错误。我已经从我的客户端FTP获得了777许可,但它仍然向我显示。

<?php
include ("login.php");
if ($_POST['submit']){


    $name = $_FILES['upload']['name'];
    $temp = $_FILES['upload']['tmp_name'];
    $type = $_FILES['upload']['type'];
    $size = $_FILES['upload']['size'];

    if (($type == "image/jpg") || ($type == "image/png") || ($type == "image/gif") || ($type == "image/jpeg")){
        if  ($size <= 1000000){

                move_uploaded_file($temp,$name);
                echo "<img src='$name'>";
            } else {
                    print"your image file is too big";
                }

        }else {
                print "this file type is not allowed!";
            }


    }else{
            header ("Location: login.php");
        }


?> 

<form action="upload.php" method="post" enctype="multipart/form-data">
File: <input type="file" name="upload">
<input type="submit" name="submit" value="Upload!">
</form>

问题:

Warning: move_uploaded_file(1 (12).jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\Hosting\8923686\html\uploadedimages\upload.php on line 13

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\phpF893.tmp' to '1 (12).jpg' in D:\Hosting\8923686\html\uploadedimages\upload.php on line 13

如何解决此问题?

3 个答案:

答案 0 :(得分:0)

首先,检查服务器上的文件权限。有时,即使您使用FTP客户端修复文件权限,也不会设置文件权限。

根据这个页面我谷歌了,似乎Godaddy改变了有关FTP上传的内容:

http://www.ozzu.com/programming-forum/recent-change-with-godaddy-php-file-uploads-t94040.html

答案 1 :(得分:0)

您的网络服务器无权访问您的本地驱动器。

  

D:\ Hosting \ 8923686 \ html \ uploadedimages \无效

使用指向文件夹的相对路径,而不是直接路径

这样的东西
move_uploaded_file($temp, "uploadedimages/$name");

答案 2 :(得分:0)

您可以尝试复制功能。 http://www.php.net/manual/en/function.copy.php

基于您的代码的示例:

$file_temp = $_FILES["upload"]["tmp_name"];
$file_name = $_FILES["upload"]["name"];

if(!copy($file_temp,"/uploadedimages//$file_name"))
echo "Error on uploading";