简体   繁体   English

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

[英]permission issue when uploading via php to a folder on my local drive

i've created a folder in my c drive (c:/artwork) that im using to upload files via a form in php, like this:我在我的 c 驱动器 (c:/artwork) 中创建了一个文件夹,我用来通过 php 中的表单上传文件,如下所示:

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

The problem is that when files are uploaded and i go to the folder and try to open a file i get the following message: Photo Gallery can't open this picture because yu do not have permission to access the file location问题是,当文件上传和我 go 到文件夹并尝试打开文件时,我收到以下消息:照片库无法打开此图片,因为您没有访问文件位置的权限

If i manually copy and paste a picture in that same folder, there are no issues.如果我手动将图片复制并粘贴到同一文件夹中,则没有问题。 I can open and view pictures perfectly!我可以完美地打开和查看图片!

Im guessing it has to be a permission issue when uploading via php, but wich?我猜想通过 php 上传时它必须是权限问题,但至于什么? How do i fix it?我如何解决它?

Thanks谢谢

edit (added code)编辑(添加代码)

$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!";
}

if you haven't setup "upload_tmp_dir" directives in php.ini then the files are being saved in temp folder.如果您尚未在 php.ini 中设置“upload_tmp_dir”指令,则文件将保存在临时文件夹中。 In your case C:\Windows\Temp if you are using IIS and therefore it inherits the permission of that directory instead of c:/public_html/discography/artwork/.在您的情况下 C:\Windows\Temp 如果您使用的是 IIS ,因此它继承了该目录的权限而不是 c:/public_html/cography/discwork/

To fix that either set the permission of Temp directory of define a another place to store tmp files in php.ini.要解决此问题,请设置临时目录的权限,在 php.ini 中定义另一个存储 tmp 文件的位置。

Try using chmod() to modify the permissions of that file.尝试使用chmod()修改该文件的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM