How can I upload a file from Google Images in PHP? -


<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 , select picture want 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 valid , uploaded.<br /> ";  echo "the image file, $filename, $filesize bytes.<br/>"; }  ?> <center>  <br /> <img src=<?php echo "\"\examples\\$filename\"";?> width="250" height="175" border="3"> </center> </font> </body> </html> 

i write both html , php code create simple upload file form.this code uploading file same computer localhost, how can change upload google images?

this little bit crude, works.

add block in file choosing page.

<!-- use url file --> <form action="upload_move_file.php" method="post"> <input type="text" name="url"> <input type="submit" value="get file url"/> </form> 

then put section in upload_move_file.php works on url rather system upload.

/* make folder wite downloads , make accessible  ** write permission web user */ $path = "files"; $uploaddir = $path.'/' ;  /* if form sent url, use */ if (isset($_post['url'])){     $url_string = $_post['url'];      /* need name url , image type */     $name = substr($url_string , strrpos($url_string ,"/") + 1 ) ;     $extension = substr($name , strrpos($name ,".") + 1 ) ;      /* download , store image in temp file */     $img = file_get_contents($url_string);      /* write file on new name */     $uploadfile = $path ."/". $name;     file_put_contents($uploadfile, $img);      /* need file size */     $img_size = filesize($path ."/". $name);          /* try loading stuff files array      ** trick 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 show */      die('success!       <center>         <br />         <img src="'.$uploadfile.'"          width="250" height="175" border="3" />     </center>');   } /* else use other idea handled local image. */ 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -