Page 1 of 4 1234 LastLast
Results 1 to 20 of 67

Thread: Upload image with link

  1. #1
    Join Date
    Jan 2004
    Location
    Miami
    Posts
    1,040

    Default Upload image with link

    This will allow you to upload an image with your link

    Sorry guys, instructions are a little messy, I am in a hurry. I have this installed for a while now and I just wanted to share.


    Alter table_prefix adv_links (use phpadmin to add those 2 new columns)

    `imagedata` mediumblob NOT NULL,
    `imagetype` varchar(100) NOT NULL default '',

    In addlink.php find (set your max_height and max_width)

    PHP Code:
     $link['linkurl'] = htmlspecialchars($link['linkurl']);
     
    $link['catid'] = intval($link['catid']);
     
    $link['keywords'] = clean_keywords($link['keywords']);
     
     
    $errors check_link_errors($link); 
    add after

    PHP Code:
    $max_height 500;
    $max_width 200;
    if (
    is_uploaded_file($_FILES['linkimage']['tmp_name']))
     {
      
    $imagetype trim(substr(strrchr(strtolower($_FILES['linkimage']['name']), '.'), 1));
      if (
    $imagetype == "jpeg" OR $imagetype == "jpg" OR $imagetype == "png")
      {
       
    // Get new sizes
       
    list($width$height) = getimagesize($_FILES['linkimage']['tmp_name']);
       
    $new_width $width;
       
    $new_height $height;
       if (
    $height $max_height) {
        
    $new_width = ($max_height $height) * $width;
        
    $new_height $max_height;
       }
       if (
    $width $max_width) {
        
    $new_height = ($max_width $width) * $height;
        
    $new_width $max_width;
       }
       
    $imagedata imagecreatetruecolor($new_width$new_height);
      }
      if (
    $imagetype == 'jpeg' OR $imagetype == 'jpg')
      {
       
    $source imagecreatefromjpeg($_FILES['linkimage']['tmp_name']);
       
    imagecopyresampled($imagedata$source0000$new_width$new_height$width$height);
       
    ob_start();
       
    imagejpeg($imagedata);
       
    $imagedata ob_get_contents();
       
    ob_end_clean();
      }
      elseif (
    $imagetype == 'gif')
      {
       
    $imagedata file_get_contents($_FILES['linkimage']['tmp_name']);
      }
      elseif (
    $imagetype == 'png')
      {
       
    $source imagecreatefrompng($_FILES['linkimage']['tmp_name']);
       
    imagecopyresampled($imagedata$source0000$new_width$new_height$width$height);
       
    ob_start();
       
    imagepng($imagedata);
       
    $imagedata ob_get_contents();
       
    ob_end_clean();
      }
      else
      {
       
    $imagedata "";
       
    $imagetype "";
      }
      if (!empty(
    $imagedata) AND !empty($imagetype))
      {
       
    $imagesql ", imagedata = '" addslashes($imagedata) . "', imagetype = '$imagetype'";
      }
     }
     else
     {
      
    $imagedata "";
      
    $imagetype "";
      
    $imagesql "";
     } 

    find
    PHP Code:
     $newlink['description'] = htmlspecialchars($newlink['description']);
     
    $newlink['linkurl'] = htmlspecialchars(trim($newlink['linkurl']));
     
    $newlink['keywords'] = clean_keywords($newlink['keywords']);
     
    $newlink['catid'] = intval($newlink['catid']);
     
    $errors check_link_errors($newlink); 
    add

    PHP Code:
    $max_height 500;
    $max_width 200;
    if (
    is_uploaded_file($_FILES['linkimage']['tmp_name']))
     {
      
    $imagetype trim(substr(strrchr(strtolower($_FILES['linkimage']['name']), '.'), 1));
      if (
    $imagetype == "jpeg" OR $imagetype == "jpg" OR $imagetype == "png")
      {
       
    // Get new sizes
       
    list($width$height) = getimagesize($_FILES['linkimage']['tmp_name']);
       
    $new_width $width;
       
    $new_height $height;
       if (
    $height $max_height) {
        
    $new_width = ($max_height $height) * $width;
        
    $new_height $max_height;
       }
       if (
    $width $max_width) {
        
    $new_height = ($max_width $width) * $height;
        
    $new_width $max_width;
       }
       
    $imagedata imagecreatetruecolor($new_width$new_height);
      }
      if (
    $imagetype == 'jpeg' OR $imagetype == 'jpg')
      {
       
    $source imagecreatefromjpeg($_FILES['linkimage']['tmp_name']);
       
    imagecopyresampled($imagedata$source0000$new_width$new_height$width$height);
       
    ob_start();
       
    imagejpeg($imagedata);
       
    $imagedata ob_get_contents();
       
    ob_end_clean();
      }
      elseif (
    $imagetype == 'gif')
      {
       
    $imagedata file_get_contents($_FILES['linkimage']['tmp_name']);
      }
      elseif (
    $imagetype == 'png')
      {
       
    $source imagecreatefrompng($_FILES['linkimage']['tmp_name']);
       
    imagecopyresampled($imagedata$source0000$new_width$new_height$width$height);
       
    ob_start();
       
    imagepng($imagedata);
       
    $imagedata ob_get_contents();
       
    ob_end_clean();
      }
      else
      {
       
    $imagedata "";
       
    $imagetype "";
      }
      if (!empty(
    $imagedata) AND !empty($imagetype))
      {
       
    $imagesql ", imagedata = '" addslashes($imagedata) . "', imagetype = '$imagetype'";
      }
     }
     else
     {
      
    $imagedata "";
      
    $imagetype "";
      
    $imagesql "";
     } 
    still in addlink.php locate the below and do the changes in red

    $db->query_write("
    INSERT INTO " . TABLE_PREFIX . "adv_links
    (catid, name, linkurl, description, keywords, linkrecipurl, valid, open, username, userid, dateline, ipaddress, imagedata, imagetype)
    VALUES (
    $link[catid],
    '" . $db->escape_string($link['name']) . "',
    '" . $db->escape_string($link['linkurl']) . "',
    '" . $db->escape_string($link['description']) . "',
    '" . $db->escape_string($link['keywords']) . "',
    '" . $db->escape_string($link['linkrecipurl']) . "',
    $valid,
    1,
    '" . $db->escape_string($vbulletin->userinfo['username']) . "',
    " . $vbulletin->userinfo['userid'] . ",
    " . TIMENOW . ",
    '" . $db->escape_string(IPADDRESS) . "',
    '" . addslashes($imagedata) . "', '$imagetype'
    )");
    [$db->query_write("
    UPDATE " . TABLE_PREFIX . "adv_links SET
    catid = $newlink[catid],
    name = '" . $db->escape_string($newlink['name']) . "',
    linkurl = '" . $db->escape_string($newlink['linkurl']) . "',
    linkrecipurl = '" . $db->escape_string($newlink['linkrecipurl']) . "',
    description = '" . $db->escape_string($newlink['description']) . "',
    keywords = '" . $db->escape_string($newlink['keywords']) . "',
    lastupdated = " . TIMENOW . ",
    notes = '" . $db->escape_string($newlink['notes']) . "' $imagesql
    WHERE linkid = $linkid
    ");
    ###################################################
    in showlink.php after

    PHP Code:
    if (empty($_REQUEST['do']))
    {
     
    $_REQUEST['do'] = 'showlink';

    put


    PHP Code:
    // ############################### Get Image ###############################
    if ($_REQUEST['do'] == 'getimage')
    {
     
    $linkid iif(is_numeric($_GET['linkid']), $_GET['linkid'], 0);
     
    $imageinfo $db->query_first("
          SELECT imagedata, imagetype
          FROM " 
    TABLE_PREFIX "adv_links
          WHERE linkid = '
    $linkid'
          "
    );
     if (
    $linkid)
     {
      
    header('Cache-control: max-age=31536000');
      
    header('Expires: ' gmdate('D, d M Y H:i:s', (TIMENOW 31536000)) . ' GMT');
      
    header('Content-disposition: inline; filename=image.jpg');
      
    header('Content-transfer-encoding: binary');
      
    header('Content-Length: ' strlen($imageinfo['imagedata']));
      
    header('Last-Modified: ' gmdate('D, d M Y H:i:s', (TIMENOW)) . ' GMT');
      
    $extension $imageinfo['imagetype'];
      if (
    $extension == 'jpg' OR $extension == 'jpeg')
      {
       
    header('Content-type: image/jpeg');
      }
      else if (
    $extension == 'png')
      {
       
    header('Content-type: image/png');
      }
      else
      {
       
    header('Content-type: image/gif');
      }
     
      print 
    $imageinfo['imagedata'];
     }
     die();

    #########################################

    templates changes

    ADV_LINKS_ADD_EDIT change the form action to
    PHP Code:
    <form enctype="multipart/form-data" action="addlink.php" method="post"
    after the $customfieldbits, put in the upload form

    PHP Code:
    <fieldset class="fieldset"><legend>Link Image</legend>
    <
    div style="padding:$stylevar[formspacer]px">
    Upload an image (or change current one)<br />jpg or png will be resized to 300 pixels width if larger.<br />Gif images <b>must</bbe 300 px wide or under or image will be deleted.<br />
    <
    input class="bginput" name="linkimage" size="40" type="file" />
    </
    div>
    </
    fieldset
    in ADV_LINKS_SHOWLINK (now use your imagination where you want image to display. My template has been reworked completely, so you have to figure it out, it's just plain HTML
    PHP Code:
    <if condition="!empty($link[imagedata])">
    <
    img style="padding: 0px" src="showlink.php?$session[sessionurl]do=getimage&linkid=$link[linkid]/>
    </if> 
    Last edited by Lionel; 04-19-2007 at 05:19 PM.

  2. #2

    Default Re: Upload image with link

    Very cool. Would be great if such cool features were part of the default.

  3. #3
    Join Date
    Jan 2007
    Posts
    209

    Default Re: Upload image with link

    This works great.

    I do have a concern regarding storing the images in the db. I am planning on having thousands of links in the directory, all with a picture. I have a feeling it will cause my db to become massive once we have added the links. Is this a legitimate concern?

    Cheers and thanks for the mod,
    Ian

  4. #4
    Join Date
    Jan 2004
    Location
    Miami
    Posts
    1,040

    Default Re: Upload image with link

    should not be a problem. I have thousands of images stored in my gallery db.

  5. #5
    Join Date
    Apr 2006
    Posts
    17

    Exclamation Re: Upload image with link

    hello, sorry for my bad english

    i have made the changes but i get this error 1136:

    Datenbankfehler in vBulletin 3.6.4:

    Invalid SQL:

    INSERT INTO vb3_adv_links
    (catid, name, linkurl, description, keywords, linkrecipurl, valid, open, username, userid, dateline, ipaddress)
    VALUES (
    4,
    'Hallo Gemeinschaft',
    'http://www.xxx.info',
    'test',
    '',
    '',
    1,
    1,
    'Flckchen',
    87,
    1170942892,
    xxx
    '\0JFIF\0\0\0\0\0\0\0>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality
    \0C\0

    $.\' \",#(7),01444\'9=82<.342\0C

    2!!22222222222222222222222222222222222222222222222222\0\0K\0d\"\0\0\0\0\0\0\ 0\0\0\0\0\0
    \0\0\0\0}\0!1AQa\"q2‘#BR$3br‚
    %&\'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š \0\0\0\0\0\0\0\0
    \0\0\0w\0!1AQaq\"2B‘ #3Rbr
    $4%&\'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š \0\0\0?\0Kq*ii%’wc’Pd“kKubx]’\0\0W>6›]<?f–*†7$*B#Gid\0\0t#Iu™>.†KY|‘…Y/-œ€Z!‰h$w>MštDŽ/1qBxrbG ud#F[V+=kh•Y_Pœ2\0žMZ=Œ˲…R`Tœ2Gjm!››\\UŽȹžk›ˆ
    rg‘$Fn`I`…€Y i›W[-X••U,㳸€ u=*d#F”0Gl‘Iw2\'’‘c 3X2F6–Ÿ—5NǵK[…]Il`H¢—D(m‹1.’Fuk{–f–)$‰L\"UݸsZݽ*.œ‰(™-f`6rr6œJҲ*6TQZ\' Ž{\0\0^P\0賮|
    &^]ܤ`=ŠŠ UŸ\0‘\0^q\"6˧h6!–.fgi|’1%ˆ0̽˜u[xu+O-m‘™y[v7st—‹žt\"cvpqž׾:M! p$Šyp0UP6*Zs{1$k-zX2<pn›“†P2Vg’?……n<Z–la\"“G‘䏨>u…R!\\F\"e(RD9-ƒT46Zš5›E’Pp)FŒ ’۲€x›:}G=u†-.b6O `3l;\\ŽCjH&mt*F —wk8IhD #‚|oO<–i*ݤ–XP;pS‚
    Z>_ˣ‚;ss\\<OP(E•\'x,qJ]F]U– ŸL㵽A<ltB9JԏȨ+Pjy3#%M^L’‚<\0\\ž“Me4{H’Km>
    i=ķr8P‡95Šuv,‡o•›1m$eqSji-?Zy[*XK˜n!yE%FR]Xg<\0š]
    Oէԯ(–+`y*…~uϿ5<‡9=^‰OŠŠEZ_+פ_*m‡\0ŠWJ\0X \0*2c}de5’*A5`Ž„z9S#™U[UŽ5‘mհV2w\0}sM_ k V25c*‘™˜Arœ%W9<TrxkE–W
    Z†Fcm…y<ŒuBnxŒ);zqƒšz̬”+‚9‹˸xcF7 o+L+I%̮“f9#qO֏r\\jžW•\'‘—\0?*A\02>ee-% plˆŽ(V\0‹4Šœ
    ‡\0|տ]7ŸnBŒ7_n=™G™G3\"722KfPZ`SElxa\0—\0?*}ƒ‡\0Š_K \0tUgWž&Ki†q”€ ž™\'{(
    ].ƒ_)‡2^-h…pdgP8*;tžLci,W—ŒlSFDP `V
    ž(G7Œn3m!\"A#H[email protected]|ŒdntMr}3H’,*—*OH)Ža•_- ֲͩE:uœfeYSœ *6…X“_]5wŠ}šwx™ŽH~M’Qœ’YnᴹX.‚}۷gڏy*€]7wRq&n*2[ݻQX![ž=;r]\0ᷲ滦Xov{ky۷
    [-ҡ›XK)m<=,(sš2m‘‚ œtGŠ$–A‰;W O@+–KwMN5’z›˜UUII`yv\"[A(]•’Fv?VbIMqImi-\0_1—‘›
    yn9#D7†6tB3AMR2Ži8oi%šRKwˆ%i$iN RC&:žk}f[Œشlۏoa4Va‡†)}3VѴRn
    0H=A˴oRŠ0p8V!տ\0‘6•OfX›v\0+wL3O}/N”bM>~hӁš!տ\0‘C\0#(Œgz^™%œvri֏kܐ*QO<…•[‘M’$
    028$W\0 *\0?\0|[G`u<kjN,“’e€\'ˆ@[~?$?޹Œu_Huo…\0\0
    nGzt!KHcVq… ‚:“ƒT,<+Ilw˜a00B2{#\0 *\0?\0|[BAŽ\"(TR#n6\0„‡V\0Ÿ\0GQ\0 *\0?\0|}MxgS–Ig.dVZ', 'jpg'

    );

    MySQL-Fehler : Column count doesn't match value count at row 1
    Fehler-Nr. : 1136
    Datum : Thursday, February 8th 2007 @ 02:54:52 PM
    Skript : http://www.xxx.info/links/addlink.php
    Referrer : http://www.xxx.info/links/addlink.php
    IP-Adresse : xxx
    Benutzername : Flckchen
    Klassenname : vb_database
    whrer is the problem ? i thoink in imagetype but i dont know it

    can you help me please ??

  6. #6
    Join Date
    Jan 2004
    Location
    Miami
    Posts
    1,040

    Default Re: Upload image with link

    I use GD. Did you alter your database?
    Alter table_prefix adv_links (use phpadmin to add those 2 new columns)

    `imagedata` mediumblob NOT NULL,
    `imagetype` varchar(100) NOT NULL default '',

  7. #7
    Join Date
    Apr 2006
    Posts
    17

    Default Re: Upload image with link

    yes i have..... i have found the problem, it was a "," in the addlink.php

    sorry.....

  8. #8
    Join Date
    Oct 2005
    Location
    Manassas, Virginia
    Posts
    139

    Default Re: Upload image with link

    Quote Originally Posted by frosch68 View Post
    yes i have..... i have found the problem, it was a "," in the addlink.php

    sorry.....
    Where did you find the error? What line? I'm getting a very similar database error.


    I dont understand the "default" part for image type either. What value should I put? There is a note in phpmyadmin when using defaults to use the format: a

    Can someone tell me what this means please?

    Thanks,
    Jim

  9. #9
    Join Date
    Oct 2005
    Location
    Manassas, Virginia
    Posts
    139

    Default Re: Upload image with link

    Nevermind... LOL I found the problem. For some reason, the comma after the IPADDRESS field got removed or was not added in the query.

    It's working now.

    Jim

  10. #10

    Default Re: Upload image with link

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/.mannaz/blastup/indexspot.com/reviews/addlink.php on line 458

    i got this problem and i installed it on the newest version of links directory?
    help?thanx

  11. #11
    Join Date
    Jan 2004
    Location
    Miami
    Posts
    1,040

    Default Re: Upload image with link

    you need to follow instructions to the letter. I just reinstalled it for 2.01, using the instructions I posted here because I overwrote my files. If you do you won't have any errors.

    Make sure you don't miss a comma. I just made the changes bigger.
    Last edited by Lionel; 03-02-2007 at 12:23 AM.

  12. #12
    Join Date
    Mar 2004
    Location
    Traveling...
    Posts
    56

    Default Re: Upload image with link

    HINT: This would be a great feature for Brian to add to the next version of vBa Links Directory.

  13. #13

    Default Re: Upload image with link

    Quote Originally Posted by Lionel View Post
    you need to follow instructions to the letter. I just reinstalled it for 2.01, using the instructions I posted here because I overwrote my files. If you do you won't have any errors.

    Make sure you don't miss a comma. I just made the changes bigger.
    ok i will reinstall it.. thanx..

  14. #14
    Join Date
    Jan 2004
    Location
    Miami
    Posts
    1,040

    Default Re: Upload image with link

    Quote Originally Posted by Andy R View Post
    HINT: This would be a great feature for Brian to add to the next version of vBa Links Directory.
    I too would love to see this added so I don't have to edit after each upgrade. I am even planning to further improve on this by charging for uploading, and display first, in bold, those who paid.

  15. #15

    Default Re: Upload image with link

    thanks this hack is great.. it works now..

  16. #16

    Lightbulb Re: Upload image with link

    Quote Originally Posted by Lionel View Post
    you need to follow instructions to the letter. I just reinstalled it for 2.01, using the instructions I posted here because I overwrote my files. If you do you won't have any errors.

    Make sure you don't miss a comma. I just made the changes bigger.
    yea i put it in the wrong database.. that is why.. um... is there a way to show it in the browselinks.php section and newest links section and random links.. so you will see a list of links with images.. I been trying to do this..and trying to put the image next to the statusicons .. but for some reason it don;t work.. and only works in showlinks.php.. i can;t get it.. could you help thanx...

  17. #17

    Default Re: Upload image with link

    you are da bomb man for giving people this script..

  18. #18

    Default Re: Upload image with link

    also is there a way to put the browse button.. on the administor panel..
    under vBa Links Directory> Add links.. I also tried to do this.. but i am such an amateur. i just started like vbulletin this week.. and not really familiar with the codings..

  19. #19
    Join Date
    Jan 2004
    Location
    Miami
    Posts
    1,040

    Default Re: Upload image with link

    Quote Originally Posted by blastup View Post
    yea i put it in the wrong database.. that is why.. um... is there a way to show it in the browselinks.php section and newest links section and random links.. so you will see a list of links with images.. I been trying to do this..and trying to put the image next to the statusicons .. but for some reason it don;t work.. and only works in showlinks.php.. i can;t get it.. could you help thanx...
    sure you could show it in any of the adv_links_linkbit display, it's in the database. You just need to get the image also when you get the other info, and then add it to the template..... but you have to make sure those images are not big.

  20. #20

    Default Re: Upload image with link

    do i need to edit anything in the browselinks.php for it to show the list of images? or just the xml template? or both?

Page 1 of 4 1234 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •