image host script help

Discussion in 'PHP' started by phaseman, Feb 25, 2009.

  1. #1
    I have an image host script installed, everything is working fine. I wish to change a feature and need some help, after I upload a picture it creates a fhumbnail which can then be posted in a forum and so forth, a fhumbnail is then created in the forum and when clicked on it will take you to the original photo to view the full size..........

    What I would like is to have the original size posted directly in the forum similar to using tinypic please advice me what I need to change.

    Thanks
     
    phaseman, Feb 25, 2009 IP
  2. ebizaustralia

    ebizaustralia Peon

    Messages:
    91
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    without seeing the code none of us can advise you.Its better to hire someone
     
    ebizaustralia, Feb 25, 2009 IP
  3. darkblue

    darkblue Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    darkblue, Feb 25, 2009 IP
  4. phaseman

    phaseman Active Member

    Messages:
    244
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #4
    <?php
    $target = "upload/";
    $thumb = "thumbs/";
    $ext = substr(strrchr(basename( $_FILES['uploaded']['name']), "."), 1);
    $ext = strtolower($ext);
    $randName = md5(rand(1,9999999) * time() * date(DATE_RFC822)+rand(1,9999999));
    $target = $target . $randName . '.' . $ext;
    $thumb = $thumb . $randName . '.' . $ext;
    $eror="No Error";
    $ok=1;
    function createthumb($name,$filename,$new_w,$new_h)
    {
    	$system=explode(".",$name);
    	if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
    	if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
    	if (preg_match("/gif/",$system[1])){$src_img=imagecreatefromgif($name);}
    	$old_x=imageSX($src_img);
    	$old_y=imageSY($src_img);
    	if ($old_x > $old_y) 
    	{
    		$thumb_w=$new_w;
    		$thumb_h=$old_y*($new_h/$old_x);
    	}
    	if ($old_x < $old_y) 
    	{
    		$thumb_w=$old_x*($new_w/$old_y);
    		$thumb_h=$new_h;
    	}
    	if ($old_x == $old_y) 
    	{
    		$thumb_w=$new_w;
    		$thumb_h=$new_h;
    	}
    	$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
    	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
    	if (preg_match("/png/",$system[1]))
    	{
    		imagepng($dst_img,$filename); 
    	} else {
    		imagejpeg($dst_img,$filename); 
    	}
    	imagedestroy($dst_img); 
    	imagedestroy($src_img); 
    }
    
    
    //$uploaded_size=filesize($target);
    include("header.php");
    
    //This is our size condition
    if ($uploaded_size > 3500000)
    {
    $eror="Your file is too large.<br>";?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      	<tr>
      	 	<th scope="col"><?php echo $eror; ?></th>
     	</tr>
    </table>
    <?php
    $ok=0;
    }
    
    //This is our limit file type condition
    if ($ext != "gif" && $ext != "jpg" && $ext != "jpeg" && $ext != "png") {
    $ok=0;
    $eror="You may only upload image files files.<br>";?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      	<tr>
      	 	<th scope="col"><?php echo $eror; ?></th>
     	</tr>
    </table>
    <?php
    $ok=0;
    }
    
    //Here we check that $ok was not set to 0 by an error
    if ($ok==0)
    {
    $eror="Sorry your file was not uploaded";?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      	<tr>
      	 	<th scope="col"><?php echo $eror; ?></th>
     	</tr>
    </table>
    <?php
    }
    
    //If everything is ok we try to upload it
    else
    {
    if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
    {
    createthumb($target,$thumb,100,100);
    $eror="The file ".basename( $_FILES['uploadedfile']['name']). " has been uploaded";?>
    <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
    </script>
    <script type="text/javascript">
    _uacct = "UA-2325571-1";
    urchinTracker();
    </script>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      	<tr>
      	  <th colspan="2" scope="col"><?php include("adsense2.php"); ?></th>
      </tr>
      	<tr>
      	 	<th width="300px" scope="col"><a href="<?php echo $website.'/view.php?image='.$randName . '.' . $ext?>"><img src="<?php echo $thumb ?>" width="100" height="100"></a></th>
     	    <th width="" scope="col"><form name="form1" method="post" action="">
     	      <label></label>
     	      <label class="footer"></label>
     	      <p>
     	        <label class="footer">Forum link to image:
                <input name="textfield2" type="text" value="[URL=<?php echo $website.'/view.php?image='.$randName . '.' . $ext ?>]CLICK FOR IMAGE[/URL]" size="50">
                </label>
     	        Just copy and paste 
     	      </p>
     	      <p>
     	        <label class="footer"></label>
    </p>
     	      <p>
     	        <label class="footer">Fhumbnail for forum :
                <input name="textfield4" type="text" value="[URL=<?php echo $website.'/view.php?image='.$randName . '.' . $ext ?>][IMG]<?php echo $website.'/'.$thumb?>[/IMG][/URL]" size="50">
                </label>
    Just copy and paste 	      </p>
     	    </form>
     	    </th>
      	</tr>
      	<tr>
      	  <th colspan="2" scope="col"><?php include("adsense2.php"); ?></th>
      </tr>
    </table>
    <?php
    }
    else
    {
    $eror="Shit, there was a problem uploading your file.";
    }
    }
    include("footer.php");
    ?>
    PHP:
    I have been able to change the code after i upload a picture

    sample code:
    [​IMG]

    Sample fhumbnail:
    [​IMG]

    If I change the word thumbs to upload it will display the full picture.
    I would like if a member upload picture he does not need to change the word and mostly likely they might not even know.

    Sample end result
    [​IMG]

    Any advice thanks........
     
    phaseman, Feb 26, 2009 IP