#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    Help improving code


    Hello, i develeoped a code (with some help, i'm a bit newby) to play a board game over internet.

    Basically, this code allows the user of the webpage to change images withuot the use of a content management software or any aditional sofware.

    It works reading from a file called cover-pic.txt and showing the image specified on that file.
    Also, if you want to change the image it shows a list of images included on the specified directory and you click on the new image you want to display and the code updates the cover-pic.txt and the html shows the new image.

    The change i want to make on the code and i'm unable to get working is having on the same image directory different cover-pic.txt files, so i can display and change several images of the same directoy without havin to create an individual directory for each image i want to display on the page.

    This is the code that shows the image (pic-gal.php)

    PHP Code:
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <style>    
                img
                {
                        border:2px #000000 solid;
                }

    </style>
    <script>
                function setCoverPic(picname,album_name)
                {
                
                    flag=confirm("Do you want to change the cover picture?");
                    if(flag==true)
                    {
                        window.location="setCoverPic.php?image_name="+picname+"&album_name="+album_name;
                    }
                    
                            
                }//end of function

    </script>

    <body>
            
            <?php
                        
    if(!isset($_GET["album_name"]))
                        {
            
    ?>
                            <table width="10%" border="0" cellpadding="10">
                                <tr align="left" valign="top">
                                    <td width="17%" height="118">    
                                    <div style="width:100%;height:100%">
                                                <?php
                                                      $album_name
    ="album1";
                                                      
    $file_name="cover-pic.txt";
                                                      
    $file_path="images/".$album_name."/".$file_name;
                                                      
                                                      if(
    file_exists($file_path))
                                                      {
                                                            
    $fp=file($file_path);
                                                            foreach(
    $fp as $line)
                                                            {
                                                                
    $cover_pic=$line;
                                                            }
                                                            
    $cover_pic_path=$album_name."/".$cover_pic;                            
                                                            
                                                      }
    //end of if                                               
                                                
    ?>
                                                <a href="?album_name=<?php echo $album_name ?>"><img src="images/<?php echo $cover_pic_path?>" width="100%" height="118" alt="<?php echo $album_name?>" title="<?php echo $album_name?>" /></a>
                                     </div>
                                     </td>
                                                
                                  </tr>
                         </table>
            
            <?php
                        
    }
                        else
                        {                    
                             
    $album_name=$_GET["album_name"];                         
                             
    $dir_path="images/".$album_name;
                             
    $dp=opendir($dir_path);
            
    ?>
            
            <table border="0">
            <?php            
                            $i
    =0;     
                             while(
    $file=readdir($dp))
                             {
                             
                                   if(
    $file!="." && $file!=".." && $file!="Thumbs.db" && $file!="cover-pic.txt" )
                                  {
                                          if(
    $i==0)
                                        {
                                            echo 
    "<tr>";
                                        }
                                          echo 
    "<td><a href=\"javascript:setCoverPic('".$file."','".$album_name."');\"><img src=images/".$album_name."/".$file." width=\"200\" height=\"200\"></a></td>";        
                                        
    $i++;
                                        if(
    $i==4)
                                        {
                                            
    $i=0;
                                            echo 
    "</tr>";
                                        }                  
                                  }
                             
                             }
    //end of while    
                             
    if($i>&& $i<4)
                             {
                                     while(
    $i<4)
                                     {
                                        echo 
    "<td>&nbsp;</td>";    
                                        
    $i++;
                                     }    
                                     echo 
    "</tr>";
                            }                 
                                                                           
            
    ?>    
            </table>        
            <?php
                        
    }//else end
            
    ?>


    </body>
    </html>

    and thsi is the code wich changes the image (setCoverPic.php)

    PHP Code:
    <?php
                $image_name
    =$_GET["image_name"];
                
    $album_name=$_GET["album_name"];
                
    $file_name="cover-pic.txt";
                
    $file_path="images/".$album_name."/".$file_name;
                
    $fp=fopen($file_path,"w");
                
    fwrite($fp,$image_name);
                
    fclose($fp);
                
    header("location:pic-gal.php?flag=1");
                
    ?>
    To have this working you must put them on the same directory and inside create a folder called images and put some pics inside it.

    Thanks, just for reading this.

    PD: Sorry the mistake with the tags
    Last edited by sertorio; October 1st, 2013 at 05:20 AM. Reason: Missing tags
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Location
    Saint-Petersburg, Russia
    Posts
    236
    Rep Power
    28
    It would be good if you edit your post and surround the code into special code tags (php) and (/php), only with square brackets.

    Chances that people would read poorly formatted long code are small enough
  4. #3
  5. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    Originally Posted by rodiongork
    It would be good if you edit your post and surround the code into special code tags (php) and (/php), only with square brackets.
    That means selecting your code in the editor and then clicking the white PHP button (next to the #), not the purple php button (which creates a link to the documentation)
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by Northie
    That means selecting your code in the editor and then clicking the white PHP button (next to the #), not the purple php button (which creates a link to the documentation)
    Sorry, sorry...

IMN logo majestic logo threadwatch logo seochat tools logo