开发者

Web site baker image upload problem

Recently I am developing website baker's module. There is one option to upload image. I am using php image upload code but give the following error and image didn't upload.

Warning: move_uploaded_file(http://localhost/wb/media/gallery/mypic.jpg) [function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections in C:\wamp\www\wb\modules\hotelmod\save_picture.php on line 84

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\phpBBBD.tmp' to 'http://localhost/wb/media/gallery/mypic.jpg' in C:\wamp\www\wb\modules\hotelmod\save_picture.php on line 84

here's the code that i use:

if (($_FILES["image"]["type"] == "image/jpeg" || $_FILES["image"]["type"] == "image/pjpeg" || $_FILES["image"]["type"] == "image/gif" || $_FILES["image"]["type"] == "image/x-png") && ($_FILES["image"]["size"] < 4000000))
    {

        // if uploaded image was JPG/JPEG
        if($_FILES["image"]["type"] == "image/jpeg" || $_FILES["image"]["type"] == "ima开发者_运维问答ge/pjpeg"){  
            $image_source = imagecreatefromjpeg($_FILES["image"]["tmp_name"]);
        }       
        // if uploaded image was GIF
        if($_FILES["image"]["type"] == "image/gif"){    
            $image_source = imagecreatefromgif($_FILES["image"]["tmp_name"]);
        }   
        // BMP doesn't seem to be supported so remove it form above image type test (reject bmps)   
        // if uploaded image was BMP
        if($_FILES["image"]["type"] == "image/bmp"){    
            $image_source = imagecreatefromwbmp($_FILES["image"]["tmp_name"]);
        }           
        // if uploaded image was PNG
        if($_FILES["image"]["type"] == "image/x-png"){
            $image_source = imagecreatefrompng($_FILES["image"]["tmp_name"]);
        }


        $remote_file =  WB_URL.'/modules/hotelmod/images/'.$_FILES["image"]["name"];
        move_uploaded_file($_FILES['image']['tmp_name'], $remote_file);
}

How can I resolve this? Thanks in advance.


You're probably trying to do something like:

move_uploaded_file($_FILES['somefile']['tmp_name'], 'http://localhost/wb/media/gallery/mypic.jpg');

This is incorrect. Attempting to write to a URL would only trigger yet another HTTP upload, which is what you're already trying to handle.

The destination/target of move_uploaded_files() must be a file system path, something like

/home/sites/yoursite/document_root/images/mypic.jpg

instead.


You're passing a URL to move_uploaded_file(). move_uploaded_file() needs a path. Not a URL. Probably something like (for windows) C:\path\to\save\uploads


You destination must be a file system path, not a URL. Its up to your web server to map URLs to filesystem paths to find the file (but of course your scripts need to know how it does that so you can create links to it).

E.g., you could configure your server to serve http://example.com/uploads/ from /srv/www/example.com/uploads/. Then you'd have your PHP script move the file to /srv/www/example/com/uploads/FOO.png.

Make sure to turn off PHP (and CGI, etc.) in your upload directory for security reasons. E.g., in Apache, you'd do:

<Directory /srv/www/example.com/uploads>
    php_admin_flag engine off
</Directory>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜