Help with PHP Upload & Base64 Encode

Discussion in 'PHP' started by GeelongTECH, Mar 27, 2011.

  1. #1
    Hey,

    I want to upload an image and it to also base 64 encode it for back up.

    I am using:
    
    <?php
    $rand = rand();
    $target = '/home/example/public_html/images/small/'.$rand.'_' . basename( $_FILES['uploaded1']['name']) ; 
    $ok=1; 
    if(move_uploaded_file($_FILES['uploaded1']['tmp_name'], $target)) 
    {$img_1 = 'yes';} 
    else {$img_1 = 'no';} 
    $img1_url = $target;
    $img1_url = str_replace('/home/example/public_html/images/small/','http://example.com/images/small/',$img1_url);/*Replace Space With -*/
    ?>
    
    PHP:
    I need it to echo the base64 code so it can be used a back.
     
    GeelongTECH, Mar 27, 2011 IP
  2. TimK

    TimK Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $encodedImg = base64_encode(imagecreatefromgif($img1_url));
    echo($encodedImg);
    
    PHP:
    Something like that should work. Then if you want to use it in HTML you must change the <img src> to
    
    echo '<img src="data:image/gif;base64,'.$encodedImg.' ">';
    
    PHP:
     
    TimK, Mar 27, 2011 IP
  3. joy1986joy

    joy1986joy Member

    Messages:
    189
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #3
    Hi
    What problem you are facing? You are not able to upload the image or not able to encode in base 64.
     
    joy1986joy, Mar 28, 2011 IP