Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Php includes not working!

    Im trying to use two includes in my HTML documents, the first one being a website gallery and the 2nd one being a logo gallery. I have made two separate PHP files websites.php
    and logos.php. I have setup my .htaccess file already and i know it is working. the problem is when i put in i can't get my second include to show up.

    here is my html code
    Code:
        <!doctype html>
        <html>
        <head>
        <meta charset="utf-8">
        <title>Untitled Document</title>
        <meta charset="utf-8">
        <title>Mirror Designs</title>
        <link href="styles.css" rel="stylesheet" type="text/css">
        <link rel="stylesheet" type="text/css" href="gallery/style.css" />
            <link rel="stylesheet" type="text/css" href="gallery/resources/fancy.css" />
        <script type="text/javascript" src="gallery/js/jquery-1.2.3.pack.js"></script>
            <script type="text/javascript" src="gallery/js/jquery.fancybox-1.0.0.js"></script>
            
            <script type="text/javascript">
            
                $(function(){
                
                    $(".photo-link").fancybox({ 'zoomSpeedIn': 500, 'zoomSpeedOut': 500, 'overlayShow': true }); 
                
                });
            
            </script>
        </head>
        
        <body id="body">
        <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" id="heading-table1">
          <tr>
            <td height="261" align="center" valign="top" bgcolor="#4A4A4A"><img src="images/logo.jpg" width="1203" height="197"  alt="Mirror Designs"/></td>
          </tr>
        </table>
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="nav" id="heading-table2">
          <tr>
            <td width="9%" align="center" bgcolor="#999999">WEBSITES</td>
            <td width="6%" align="center" bgcolor="#999999">LOGOS</td>
            <td width="6%" align="center" bgcolor="#999999">OTHER</td>
            <td width="59%" align="center">WE ARE MIRROR DESIGNS - WE MAKE SIMPLE, CLEAN AND EFFECTIVE WEBSITES</td>
            <td width="20%" align="center" bgcolor="#999999">Contact Us</td>
          </tr>
        </table>
        <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" >
          <tr>
            <td height="654" valign="top"><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" id="maintable-location">
              <tr>
                <td width="3%" height="30" align="left">&nbsp;</td>
                <td width="97%" height="50" align="left"><h1>Our Websites</h1></td>
              </tr>
              <tr>
                <td height="30" colspan="2" align="left"><?php include_once("websites.php"); ?></td>
                </tr>
              <tr>
                <td height="30" align="left">&nbsp;</td>
                <td height="30" align="left"><h1>Our Logos</h1></td>
              </tr>
              <tr>
              <td><?php include_once("logos.php"); ?></td>
              </tr>
            </table></td>
          </tr>
        </table>
        </body>
        </html>
    here is my website.php code
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    </head>
    <?php

    $variable_name = '';
    function createThumb_square($source,$dest) {
    $thumb_size = 100;
    $size = getimagesize($source);
    $width = $size[0];
    $height = $size[1];

    if($width> $height) {
    $x = ceil(($width - $height) / 2 );
    $width = $height;
    } elseif($height> $width) {
    $y = ceil(($height - $width) / 2);
    $height = $width;
    }

    $new_im = ImageCreatetruecolor($thumb_size,$thumb_size);
    $im = imagecreatefromjpeg($source);
    imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height);
    imagejpeg($new_im,$dest,100);
    }

    function createThumbName($file,$pic_format,$thumb_mask)
    {

    $pic_name_length = strlen($file);

    $pic_name_length = $pic_name_length - strlen($pic_format);

    $pic_name = substr($file, 0, $pic_name_length);

    $pic_name_thumb = $pic_name.$thumb_mask.$pic_format;
    return $pic_name_thumb;
    }

    function fileExists($dir, $file)
    {
    if ($handle = opendir($dir)) {

    while (false !== ($file_name = readdir($handle))) {
    if($file_name == $file){
    return true;
    }
    }
    return false;
    }
    }
    /* settings */
    $image_dir = 'gallery/websites/';
    $per_column = 5;

    /* step one: read directory, make array of files */
    if ($handle = opendir($image_dir)) {
    while (false !== ($file = readdir($handle)))
    {
    if ($file != '.' && $file != '..')
    {
    $file_thumb = createThumbName($file,'.jpg','-thumb');
    if(strstr($file,'-thumb'))
    {
    $files[] = $file;
    }elseif (!fileExists($image_dir,$file_thumb))
    {
    echo 'reingelaufen';
    // echo 'neuer Thumbname ist:'.” “.$file_thumb;
    createThumb_square($image_dir.$file,$image_dir.$file_thumb);
    }

    }
    }
    closedir($handle);
    }
    /* step two: loop through, format gallery */
    sort($files);
    if(count($files))
    {
    foreach($files as $file)
    {
    $count++;
    echo '<a class="photo-link" rel="one-big-group" href="',$image_dir,str_replace('-thumb','',$file),'"><img src="',$image_dir,$file,'" width="100" height="100" /></a>';
    if($count % $per_column == 0) { echo '<div class="clear"></div>'; }
    }
    }
    else
    {
    echo '<p>There are no images in this gallery.</p>';
    }

    ?>

    <body>
    </body>
    </html>
    and here is my logos.php code
    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    </head>
    <?php
    
    $variable_name = '';
    function createThumb_square($source,$dest) {
    $thumb_size = 100;
    $size = getimagesize($source);
    $width = $size[0];
    $height = $size[1];
     
    if($width> $height) {
    $x = ceil(($width - $height) / 2 );
    $width = $height;
    } elseif($height> $width) {
    $y = ceil(($height - $width) / 2);
    $height = $width;
    }
     
    $new_im = ImageCreatetruecolor($thumb_size,$thumb_size);
    $im = imagecreatefromjpeg($source);
    imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height);
    imagejpeg($new_im,$dest,100);
    }
     
    function createThumbName($file,$pic_format,$thumb_mask)
    {
     
    $pic_name_length = strlen($file);
     
    $pic_name_length = $pic_name_length - strlen($pic_format);
     
    $pic_name = substr($file, 0, $pic_name_length);
     
    $pic_name_thumb = $pic_name.$thumb_mask.$pic_format;
    return $pic_name_thumb;
    }
     
    function fileExists($dir, $file)
    {
    if ($handle = opendir($dir)) {
     
    while (false !== ($file_name = readdir($handle))) {
    if($file_name == $file){
    return true;
    }
    }
    return false;
    }
    }		
    		/* settings */
    		$image_dir = 'gallery/logos/';
    		$per_column = 5;
    		
    /* step one: read directory, make array of files */
    if ($handle = opendir($image_dir)) {
    while (false !== ($file = readdir($handle)))
    {
    if ($file != '.' && $file != '..')
    {
    $file_thumb = createThumbName($file,'.jpg','-thumb');
    if(strstr($file,'-thumb'))
    {
    $files[] = $file;
    }elseif (!fileExists($image_dir,$file_thumb))
    {
    echo 'reingelaufen';
    // echo 'neuer Thumbname ist:'.” “.$file_thumb;
    createThumb_square($image_dir.$file,$image_dir.$file_thumb);
    }
    
    }
    }
    closedir($handle);
    }		
    		/* step two: loop through, format gallery */
    sort($files);
    		if(count($files))
    		{
    			foreach($files as $file)
    			{
    				$count++;
    				echo '<a class="photo-link" rel="one-big-group" href="',$image_dir,str_replace('-thumb','',$file),'"><img src="',$image_dir,$file,'" width="100" height="100" /></a>';
    				if($count % $per_column == 0) { echo '<div class="clear"></div>'; }
    			}
    		}
    		else
    		{
    			echo '<p>There are no images in this gallery.</p>';
    		}
    		
    	?>
    	
    <body>
    </body>
    </html>
    the website.php and the logos.php are exactly the same with the exception of the picture directory. any ideas?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You need to view your error reporting.
    The problem is you are re-declaring your functions. Functions are global scope in PHP without a namespace, and as such by including the first script it indexes the symbols required for these functions, and the second one throws an error attempting to create the same function signatures.
    Fix this by separating your functions from your scripts, and then using the remaining purpose of the scripts to wrap them into functions. Your goal here is to not include an output type, but to include a script that provides the functionality to accept the input and provide just the output required. This way you will not have two separate scripts, instead you have one function which accepts input for the proper paths and whatever variable data you want, and generates the proper output based on the input.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    cylndwa (11-05-2013)

  • #3
    New to the CF scene
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the quick respons, I thought the variables might have been the issues, I am brand new to PHP this is the first time I am trying something like this.

    so now, I have 3 files for the php portion

    ../functions/galleryfuctions.php
    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    </head>
    <?php
    $variable_name = '';
    function createThumb_square($source,$dest) {
    $thumb_size = 100;
    $size = getimagesize($source);
    $width = $size[0];
    $height = $size[1];
     
    if($width> $height) {
    $x = ceil(($width - $height) / 2 );
    $width = $height;
    } elseif($height> $width) {
    $y = ceil(($height - $width) / 2);
    $height = $width;
    }
     
    $new_im = ImageCreatetruecolor($thumb_size,$thumb_size);
    $im = imagecreatefromjpeg($source);
    imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height);
    imagejpeg($new_im,$dest,100);
    }
     
    function createThumbName($file,$pic_format,$thumb_mask)
    {
     
    $pic_name_length = strlen($file);
     
    $pic_name_length = $pic_name_length - strlen($pic_format);
     
    $pic_name = substr($file, 0, $pic_name_length);
     
    $pic_name_thumb = $pic_name.$thumb_mask.$pic_format;
    return $pic_name_thumb;
    }
     
    function fileExists($dir, $file)
    {
    if ($handle = opendir($dir)) {
     
    while (false !== ($file_name = readdir($handle))) {
    if($file_name == $file){
    return true;
    }
    }
    return false;
    }
    }		
    ?>
    <body>
    </body>
    </html>
    ../includes/websites.php
    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    <link rel="stylesheet" type="text/css" href="gallery/style.css" />
    <link rel="stylesheet" type="text/css" href="gallery/resources/fancy.css" />
    </head>
    <?php
    
    
      	/* settings */
    		$image_dir = 'gallery/websites/';
    		$per_column = 5;
    		
    /* step one: read directory, make array of files */
    if ($handle = opendir($image_dir)) {
    while (false !== ($file = readdir($handle)))
    {
    if ($file != '.' && $file != '..')
    {
    $file_thumb = createThumbName($file,'.jpg','-thumb');
    if(strstr($file,'-thumb'))
    {
    $files[] = $file;
    }elseif (!fileExists($image_dir,$file_thumb))
    {
    echo 'reingelaufen';
    // echo 'neuer Thumbname ist:'.” “.$file_thumb;
    createThumb_square($image_dir.$file,$image_dir.$file_thumb);
    }
    
    }
    }
    closedir($handle);
    }		
    		/* step two: loop through, format gallery */
    sort($files);
    		if(count($files))
    		{
    			foreach($files as $file)
    			{
    				$count++;
    				echo '<a class="photo-link" rel="one-big-group" href="',$image_dir,str_replace('-thumb','',$file),'"><img src="',$image_dir,$file,'" width="100" height="100" /></a>';
    				if($count % $per_column == 0) { echo '<div class="clear"></div>'; }
    			}
    		}
    		else
    		{
    			echo '<p>There are no images in this gallery.</p>';
    		}
    		
    	?>
    	
    <body>
    </body>
    </html>
    ../includes/logos.php
    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    </head>
    <?php
    
    		/* settings */
    		$image_dir = 'gallery/logos/';
    		$per_column = 5;
    		
    /* step one: read directory, make array of files */
    if ($handle = opendir($image_dir)) {
    while (false !== ($file = readdir($handle)))
    {
    if ($file != '.' && $file != '..')
    {
    $file_thumb = createThumbName($file,'.jpg','-thumb');
    if(strstr($file,'-thumb'))
    {
    $files[] = $file;
    }elseif (!fileExists($image_dir,$file_thumb))
    {
    echo 'reingelaufen';
    // echo 'neuer Thumbname ist:'.” “.$file_thumb;
    createThumb_square($image_dir.$file,$image_dir.$file_thumb);
    }
    
    }
    }
    closedir($handle);
    }		
    		/* step two: loop through, format gallery */
    sort($files);
    		if(count($files))
    		{
    			foreach($files as $file)
    			{
    				$count++;
    				echo '<a class="photo-link" rel="one-big-group" href="',$image_dir,str_replace('-thumb','',$file),'"><img src="',$image_dir,$file,'" width="100" height="100" /></a>';
    				if($count % $per_column == 0) { echo '<div class="clear"></div>'; }
    			}
    		}
    		else
    		{
    			echo '<p>There are no images in this gallery.</p>';
    		}
    		
    	?>
    	
    <body>
    </body>
    </html>
    and finally index.html
    Code:
        <!doctype html>
        <html>
        <head>
        <meta charset="utf-8">
        <title>Mirror Designs</title>
        <link href="styles.css" rel="stylesheet" type="text/css">
        <link rel="stylesheet" type="text/css" href="gallery/style.css" />
            <link rel="stylesheet" type="text/css" href="gallery/resources/fancy.css" />
        <script type="text/javascript" src="gallery/js/jquery-1.2.3.pack.js"></script>
            <script type="text/javascript" src="gallery/js/jquery.fancybox-1.0.0.js"></script>
            
            <script type="text/javascript">
            
                $(function(){
                
                    $(".photo-link").fancybox({ 'zoomSpeedIn': 500, 'zoomSpeedOut': 500, 'overlayShow': true }); 
                
                });
            
            </script>
        </head>
        <body id="body">
        <?php include("functions/galleryfunctions.php") ?>
          <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" id="heading-table1">
          <tr>
            <td height="261" align="center" valign="top" bgcolor="#4A4A4A"><img src="images/logo.jpg" width="1203" height="197"  alt="Mirror Designs"/></td>
          </tr>
        </table>
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="nav" id="heading-table2">
          <tr>
            <td width="9%" align="center" bgcolor="#999999">WEBSITES</td>
            <td width="6%" align="center" bgcolor="#999999">LOGOS</td>
            <td width="6%" align="center" bgcolor="#999999">OTHER</td>
            <td width="59%" align="center">WE ARE MIRROR DESIGNS - WE MAKE SIMPLE, CLEAN AND EFFECTIVE WEBSITES</td>
            <td width="20%" align="center" bgcolor="#999999">Contact Us</td>
          </tr>
        </table>
        <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" >
          <tr>
            <td height="654" valign="top"><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" id="maintable-location">
              <tr>
                <td width="0%" height="30" align="left">&nbsp;</td>
                <td width="97%" height="50" align="left"><h1>Our Websites</h1></td>
              </tr>
              </table>
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td><?php require_once("includes/websites.php"); ?></td>
                </tr>
              </table><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
              <tr>
                <td width="0%" height="30" align="left">&nbsp;</td>
                <td width="97%" height="50" align="left"><h1>Our Logos</h1></td>
              </tr>
              </table><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td><?php require("includes/logos.php"); ?></td>
                </tr>
              </table></td>
          </tr>
        </table>
        </body>
        </html>
    it is some what working, its just not displaying quite properly, you can see what i mean at www.mirrordesigns.net


  •  

    Posting Permissions

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