通过php上传到我本地驱动器上的文件夹时的权限问题

时间:2011-08-12 16:05:38

标签: php file-permissions

我在我的c盘(c:/ artwork)中创建了一个文件夹,用于通过php中的表单上传文件,如下所示:

<input name="file" type="file">

问题是,当文件上传并且我转到该文件夹​​并尝试打开文件时,我收到以下消息: 照片库无法打开此图片,因为您无权访问文件位置

如果我手动复制并粘贴同一文件夹中的图片,则没有问题。我可以完美地打开和查看图片!

我猜它在通过php上传时必须是一个权限问题,但是哪个?我该如何解决?

由于

编辑(添加代码)

$destination = 'c:/public_html/discography/artwork/'; // path to the upload folder

if (is_dir($destination) && is_writable($destination)) {
    // if file already exists, ask what to do

    // upload the file  
    $ok = move_uploaded_file($_FILES['file']['tmp_name'], $destination . $_FILES['file']['name']);

    // if file uploaded, go ahead an insert record in database
    if ($ok) {
        $stmt = $conn->stmt_init(); // initialize a prepared statement

        $stmt->prepare($sql);
        $stmt->bind_param('s', $_FILES['file']['name']);
        $stmt->execute();
        $stmt->free_result(); // free the database resources for other queries

        // if success
        if ($stmt->affected_rows > 0) {
            $success = true;
        } else {
            $err_msg = $stmt->error;
        }

        $stmt->close(); // close statement  
    }

} else {
    $err_msg = "'$destination' must be a valid, writable directory!";
}

2 个答案:

答案 0 :(得分:1)

如果你没有在php.ini中设置“upload_tmp_dir”指令,则文件将保存在临时文件夹中。在您的情况下C:\ Windows \ Temp,如果您使用的是IIS,因此它继承了该目录的权限,而不是c:/ public_html / discography / artwork /。

要修复设置Temp目录的权限,定义另一个地方来存储php.ini中的tmp文件。

答案 1 :(得分:0)

尝试使用 chmod() 修改该文件的权限。