开发者

Is there any way that I could upload an image on the page to the server?

I have this code that has an image tag. The img src is equal to "https://graph.facebook.com/<?php echo $user开发者_运维百科_id; ?>/picture". Is there anyway that I could get that image file and upload it to my server using the move_uploaded_image function with php?


No, move_uploaded_image moves files that were uploaded in a POST request.

If you want to get an image from a URL you need to make an HTTP request for it, e.g. via cURL.


Using PHP's imagecreate and file_get_contents and file_put_contents, you can create a blank image, get the image from the remote URL, then replace the blank image you created.

Similar to,

    // Create a blank image 
    $imPath = "path/to/your/desired/image.jpg";
    $im = imagecreatetruecolor(180, 151);
    imagejpeg($im,$imPath);

    // Download their fb image
    $url = 'https://graph.facebook.com/' . $user['username'] . '/picture?type=large';
    $bytes = file_put_contents($imPath, file_get_contents($url));


there is no function like move_uploaded_image . correct function is move_uploaded_file.

no. you can not get image file by this function . first argument of this function is temp file name which is uploaded through Input type = file.

and another argument is the location where you want to put file....

you should refer $_FILES of php manual for more information.... http://php.net/manual/en/function.move-uploaded-file.php

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜