如何在PHP中从谷歌图片上传文件?
我编写html和php代码来创建一个简单的上传文件表单。这段代码用于将文件从同一台计算机上传到本地主机,但如何将其更改为从Google图像上传 这有点粗糙,但它是有效的 在文件选择页面中添加另一个块如何在PHP中从谷歌图片上传文件?,php,image,file-upload,image-uploading,Php,Image,File Upload,Image Uploading,我编写html和php代码来创建一个简单的上传文件表单。这段代码用于将文件从同一台计算机上传到本地主机,但如何将其更改为从Google图像上传 这有点粗糙,但它是有效的 在文件选择页面中添加另一个块 <html><head><title>Uploading Pictures</title></head> <body bgcolor="lavender"> <h3>Uploading Files</h3>
<html><head><title>Uploading Pictures</title></head>
<body bgcolor="lavender">
<h3>Uploading Files</h3>
<form
enctype="multipart/form-data"
action="upload_move_file.php"
method="post">
Browse and select the picture you want to upload: <br />
<input name="picture_file" type="file" />
<br />
<input type=submit value="Get File"/>
</form>
</body>
</html>
(The PHP Script)
<html><head><title>File Uploads</title></head>
<body bgcolor="#33ff33">
<font face="verdana" size="+1">
<?php
echo "The uploaded file is: ", $_FILES['picture_file']
['tmp_name'], "<br />";
$filename=$_FILES['picture_file']['name'];
$filesize=$_FILES['picture_file']['size'];
$directory='C:\wamp\www\examples\\';
$uploadFile = $directory . $filename;
echo "The moved file is: $uploadFile<br />";
if (move_uploaded_file($_FILES['picture_file']['tmp_name'],$uploadFile)){
echo "The file is valid and was successfully uploaded.<br /> ";
echo "The image file, $filename, is $filesize bytes.<br/>";
}
?>
<center>
<br />
<img src=<?php echo "\"\examples\\$filename\"";?>
width="250" height="175" border="3">
</center>
</font>
</body>
</html>
然后在upload\u move\u file.php中放置一个部分,该部分在url上工作,而不是在系统上载上工作
<!-- use a url to get the file -->
<form action="upload_move_file.php" method="post">
<input type="text" name="url">
<input type="submit" value="Get file from url"/>
</form>
纯HTML可以上传文件:O?共享上传\移动\文件.php代码here@Mr.Alien对不起,有点长。不管怎样,我会编辑我的问题。@Mr.Alien你知道吗?
/* make a folder to wite the downloads to and make it accessible
** write permission for the web user */
$path = "files";
$uploaddir = $path.'/' ;
/* if your form sent the url, use something like this */
if (isset($_POST['url'])){
$url_string = $_POST['url'];
/* you will need the name from the url and image type */
$name = substr($url_string , strrpos($url_string ,"/") + 1 ) ;
$extension = substr($name , strrpos($name ,".") + 1 ) ;
/* download and store the image in a temp file */
$img = file_get_contents($url_string);
/* Write the file over to the new name */
$uploadfile = $path ."/". $name;
file_put_contents($uploadfile, $img);
/* you will need the file size */
$img_size = filesize($path ."/". $name);
/* You could try loading that stuff into FILES array to
** trick the upload script.
$_FILES['picture_file']['name'] = $name;
$_FILES['picture_file']['type'] = "image/$extension";
$_FILES['picture_file']['size'] = $img_size;
$_FILES['picture_file']['tmp_name'] = $uploadfile;
$_FILES['picture_file']['error'] = '';
OR just show it */
die('Success!
<center>
<br />
<img src="'.$uploadfile.'"
width="250" height="175" border="3" />
</center>');
} /* else use the other idea that handled the local image. */