file_puts_content permission denied on Windows 7 WAMP

元气小坏坏 提交于 2019-12-24 19:48:34

问题


I am trying to use file_put_contents on my local website to download some images from a website and save them to the C:\ drive. However when running the script I get an error

file_put_contents(C:\product_images\A): failed to open stream: Permission denied

I have full permission for the product_images folder and also the A folder inside.

I know I could just chmod in ubuntu but not sure what I could do with Windows. I just right clicked and selected properties and made sure all the users had all the permissions applied

    public function showImage() {

    $product_image = ['/ABCD/ABCD.jpg','/ABCDE/ABCDE.jpg'];

    foreach($product_image as $product_images) {
        $url = "http://images.url.com/product_images" . $product_images  ."";
        $letter = substr($product_images, 1, 1);
        $folder = 'C:\product_images\ ' .$letter . '';
        $new_folder = str_replace(' ', '', $folder);
        file_put_contents($new_folder, file_get_contents($url));
    }

    $success = "Success!";

    return $success;
}

回答1:


    foreach($product_image as $product_images) {
        $url = "http://images.com/product_images" . $product_images  ."";

        $test = explode("/", $product_images);

        $folder = 'C:\product_images\ ' . $test[2] . '';

        $new_folder = str_replace(' ', '', $folder);

        $newer_folder = str_replace('/', '\\', $new_folder);

        file_put_contents($newer_folder, file_get_contents($url));

        echo '../product_images/' . $test[2] . '';
        echo '<br />';
    }



回答2:


file_put_contents works with URLs only if allow_url_fopen is on ("1"). Check it with

ini_get("allow_url_fopen");

Also notice that while your writing folder might have the required permissions, the parent folder may NOT. Both (possible) folders should have the permissions.

You can also test the folder if its writable (through is_writable)



来源:https://stackoverflow.com/questions/23893823/file-puts-content-permission-denied-on-windows-7-wamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!