Upload to imageshack

Discussion in 'PHP' started by userman, Jul 11, 2010.

  1. #1
    Hi,

    I have a script for upload images to imageshack from my website. But the script work 1 hosting yes and another hosting no :( why another hosting dont work? i have enable cURL support in the another hosting...

    I get error: ;type=image/jpeg
    and the foto.jgp exist!!!

    Who can help me please?

    <?php 
    ini_set("display_errors","On"); 
    //$ch = curl_init("http://www.imageshack.us/transload.php"); 
    //$ch = curl_init("http://www.imageshack.us/index.php"); 
    
    function getFileType($filename) { 
                $fparts = explode(".",trim($filename)); 
                $stype = strtolower($fparts[count($fparts)-1]); 
                $type = ((($stype=="jpg") || ($stype=="jpeg"))?"jpeg":$stype); 
                return "image/".$type; 
    } 
    
    $ch = curl_init("http://www.imageshack.us/upload_api.php"); 
    
    $post['xml']='yes'; 
    $filename = "foto.jpg"; 
    $type = getFileType($filename); 
    //$post['url']=$url; 
    $post['fileupload']='@'.$filename.';type='.$type; 
    
    $post['rembar']="1"; 
    $post['login']="3a0987afa783b69fc1f7058ca503ea80"; 
    $post['cookie']="3a0987afa783b69fc1f7058ca503ea80"; 
    
    
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 300); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: ')); 
    $result = curl_exec($ch); 
    curl_close($ch); 
    if (strpos($result, '<'.'?xml version="1.0" encoding="iso-8859-1"?>') === false) { 
            echo 'failed'; 
            print_r($result); 
    } else { 
           print_r($result); 
    } 
    echo '@'.$filename.';type='.$type; 
    ?>
    PHP:
     
    userman, Jul 11, 2010 IP
  2. userman

    userman Active Member

    Messages:
    158
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    who can help me?

    i can pay 5$ via paypal...
     
    userman, Jul 12, 2010 IP
  3. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think you're referencing the filename wrong. Is one server windows and one nix' by any chance?
    Get the full path of the foto.jpg, then try:
    
    // for example...
    $filename = 'C:\www\htdocs\images\foto.jpg'; 
    
    // instead of this one:
    $filename = "foto.jpg"; 
    
    PHP:
     
    Deacalion, Jul 13, 2010 IP