开发者

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

i've created 开发者_Python百科a folder in my c drive (c:/artwork) that im using to upload files via a form in php, like this:

<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

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? 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. 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/.

To fix that either set the permission of Temp directory of define a another place to store tmp files in php.ini.


Try using chmod() to modify the permissions of that file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜