Saturday, June 2, 2012

copy image using wget PHP

Hello everyone,
I have just written a PHP script to wget any image.
All you need to do is get the full path of your image e.g. is path to google logo.
So now lets wget google's logo.


$mainimage = ""; //this would be the path of your live image which you want to download

$thebasename =  basename($mainimage); //here we will get logo3w.png i.e. name of file

$filename = explode(".", $thebasename); //explode it with extention
do {
if($i > 0) $filename[0]++;
else $filename[0] = $filename[0].$i;
    }while(file_exists("tmp_cover/".$filename[0].".".$filename[1])); //typical do while to check for unique file name
 $image_dir = "tmp_cover/"; //this will be your directory where you want to save your image
 $fresh_file = $filename[0].".".$filename[1]; //this is our renamed file if file already exists
 $image_drs = $image_dir.$fresh_file; //i have concatinated the path so it becomes easier to use in wget function
 system("wget -q \"$mainimage\" -O $image_drs");  //image uploaded with wget -q

 1)Please check if your wget version is wget v1.12 and php is php v5.3.1 or greater.
 2)Give full permissions to your files (chmod 777 your_dir) or use filezilla client to give full permission to your folder.
 3)I have created tmp_cover folder at /opt/lampp/htdocs with 777 permissions.



  1. This technical post helps me to improve my skills set, thanks for this wonder article I expect your upcoming blog, so keep sharing..
    PHP Course in Chennai


  2. In recent days Angular plays vital role to loading your site content in a fastest way, so it’s a required skill for everyone, thanks for sharing this useful information to our vision keep blogging.
    Angularjs training in chennai

  3. Awesome! Education is the extreme motivation that open the new doors of data and material. So we always need to study around the things and the new part of educations with that we are not mindful.

    angularjs Training in marathahalli

    angularjs interview questions and answers

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in chennai

    automation anywhere online Training

  4. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 

    Java training in USA

    Java training in Bangalore | Java training in Indira nagar

    Java training in Bangalore | Java training in Rajaji nagar

    Java training in Bangalore | Java training in Marathahalli

  5. This is ansuperior writing service point that doesn't always sink in within the context of the classroom. In the first superior writing service paragraph you either hook the reader's interest or lose it. Of course your teacher, who's getting paid to teach you how to write an good essay, 
    python training Course in chennai
    python training in Bangalore
    Python training institute in bangalore

  6. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.

    rpa training in chennai
    rpa training in bangalore
    rpa course in bangalore
    best rpa training in bangalore
    rpa online training

  7. Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.
    Best AWS Training in Chennai | Amazon Web Services Training in Chennai
    AWS Training in Bangalore | Amazon Web Services Training in Bangalore
    Amazon Web Services Training in Pune | Best AWS Training in Pune