有什么方法可以将页面上的图像上传到服务器?
问题描述:
我有这个代码有一个图像标记。 img src等于"https://graph.facebook.com/<?php echo $user_id; ?>/picture"
。无论如何,我可以得到该图像文件,并使用PHP的move_uploaded_image
函数将其上传到我的服务器?有什么方法可以将页面上的图像上传到服务器?
答
使用PHP的imagecreate
和file_get_contents
和file_put_contents
,您可以创建一个空白图像,从远程URL获取图像,然后替换您创建的空白图像。
类似,
// 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));
答
有像move_uploaded_image没有功能。正确的功能是move_uploaded_file。
没有。您无法通过此功能获取图像文件。 该函数的第一个参数是通过Input type = file上传的临时文件名。
和另一种说法是要放文件的位置....
你应该参考PHP手册中_FILES $以获取更多信息.... http://php.net/manual/en/function.move-uploaded-file.php