Home > PHP > Remote Upload To Imageshack.Us With PHP+cURL

Remote Upload To Imageshack.Us With PHP+cURL


Advertisement



PHP supports libcurl since V 4.0.2, a library created by Daniel Stenberg (more information go here), that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP’s ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.

Now with cURL we trying to make a script that post images to Imageshack.Us via remote upload and return direct link of images. Here the source code to download.

Update Scipt! Please download new version – 20 December 2009.

Download Code

Pass : smileylover.com

This script should work and return direct link of images that being upload. If the result is empty (error with cURL) it will return Something went wrong with Imageshack?, but if result is empty for preg_match_all function it will return Imageshack.Us Remote Upload Failed Because They Change Layout Again! and send email to your email. Just announcement.

Usually, there’s an error with preg_match_all because Imageshack.Us is change their HTML tag regularly (i think) to avoid script like this (Hey with this script same with block their ads :p ). If an error occurs just come back to here to get update with working script.

DEMO

Regards.

nb: i prefer imageshack.us because they have a lot of bandwith. they allow us to use their bandwith 300MB/hour per single image!

Related posts:

  1. Text2Image (PNG) Generator – Free Online Generator – Free Download!
  2. Change Adsense Publisher ID In Other Site With PHP and cURL
  1. Remzi Duman
    February 13th, 2009 at 00:31 | #1

    hi, cant we get a simple image upload script with using this code without writing any url-img.
    like in tinypic or imageshack mainpage, but the site automaticly upload pic to imageshack like in this code…

  2. Ivan
    February 20th, 2009 at 17:40 | #2

    That server uses for this script in the demo?
    Is it a free?
    What is it?

    I already tried with 000webhost.com and freehostia and I can“t make it work.

    any help?

    Curl is enabled on my server.

    :(

  3. Admin
    March 8th, 2009 at 18:49 | #3

    no i use paid server :)

    anyway .. 000 is work :)

    for all … plesae update this script with this changes ….

    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);  
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

    find similiar code like above and replace with that ones :)

    and this one …

    if(preg_match_all("#\<a style\=\'font\-size\: 15pt\;\' href\=\'(.*)\' rel\=\"nofollow\"\ rel="nofollow">#", $result, $matches)) {

    regards.

  4. ric
    March 9th, 2009 at 21:52 | #4

    nothing works, even updates with php syntax errors…

    rel=”nofollow” – > rel=\”nofollow\”

  5. Admin
    March 10th, 2009 at 16:25 | #5

    @ric

    sorry .. it’s seems like WP reformat my code ….. please remove rel=”nofollow” extra in last code …

    regards

    you can see it working in http://imageremoter.co.nr

  6. March 16th, 2009 at 17:44 | #6

    Hey i did like this
    <?php

    $rwimg = explode(“[IMG]“,$result);
    $rw1 = explode(“[/IMG]“,$rwimg[1]);
    $viewimg = $rw1[0];

    echo “”;

    ?>

    No ways to escape the value even any change in layout!

  7. March 16th, 2009 at 17:45 | #7

    $rwimg = explode(“[IMG]“,$result);
    $rw1 = explode(“[/IMG]“,$rwimg[1]);
    $viewimg = $rw1[0];

    echo $viewimg;

    • Admin
      March 18th, 2009 at 10:46 | #8

      Thnx for suggestion :)
      may i see ur full code?

      regards :D

  8. zzz
    April 16th, 2009 at 10:51 | #9

    Hi admin can you implement new api based system

    post link
    [code]http://www.imageshack.us/upload_api.php?url=http://imageshack.us/images/greylogo.png[/code]

    ???

    http://reg.imageshack.us/content.php?page=developer

    • Admin
      April 16th, 2009 at 14:45 | #10

      sure i cant :)

      just parse xml to php …. but i need more times .. .bcoz i have a job that must to finished right now..

      regards …

  9. zener
    May 5th, 2009 at 00:51 | #11

    Hi, can you write me your server config please? I try your script on 3 servers but it doenst work :( cURL is working, but upload file with cURL isnt working. Thank you :)

    • Admin
      May 9th, 2009 at 04:07 | #12

      i use standard config :)

      btw whats the warning?

      regards

      • zener
        May 10th, 2009 at 14:04 | #13

        Warning: Warning! Image type not valid or supported.
        I try the some image – on your demo is it working. But on my website not.

        I really dont know where is fault. I wrote my own app and I am using binary curl through exec and it is working.

        • Admin
          May 10th, 2009 at 14:56 | #14

          sorry …..

          u can change the code to be like this … find the smiliar code :D

              //open connection  
          	    $ch = curl_init();  
           
          	    //set the url, number of POST vars, POST data  
          	    curl_setopt($ch,CURLOPT_URL,$CURL_URL);  
          	    curl_setopt($ch,CURLOPT_POST,count($fields));  
          	    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
          	    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
          	    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);    
          	    $result = curl_exec($ch);  
          	    curl_close($ch); 
           
          		    if (empty($result))
          		    {
          		        print "Something went wrong with Imageshack?";
          		    }
          		    else
          		    {
          		        // Find the Hosted Image Link
          		        if(preg_match_all("#\<a>#", $result, $matches)) {   
           
          				echo '<b>'.$x.'</b> ';
          				echo '<i>original : '.$link.' </i>';
          				$x++;
           
          				} else {
           
          				echo '<b>'.$x.'</b> ';
          				echo '<i>source : '.$link.' </i>';
          				$x++;
           
          				}
           
          		    }

          regards :)

          • Ammy
            June 5th, 2009 at 23:51 | #15

            I’ve tried replacing the code with that, but now there is no link to the hosted image, only the original image url.

          • Admin
            June 6th, 2009 at 03:31 | #16

            soons, i’ll upload a full code here :)

            regards

  10. May 9th, 2009 at 07:50 | #17

    Warning! Image type not valid or supported.

Comment pages
  1. No trackbacks yet.