Code Upgrade

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sertorio
Forum Newbie
Posts: 1
Joined: Mon Sep 30, 2013 9:20 am

Code Upgrade

Post by sertorio »

Hello everyone.
as long as i'm a php newby i'been able to crate a small code but i need some help to upgrade it and don't know how.

this code allows a user to change a image on a webpage without using any content management software and without having any administration privileges.
The user must only click on the image and select the image he wish, and the code changes the image on the webpage. Obviously the user chooses the image from a predefined galley.

as you can see, the code reads the current image from a file called cover-pic.txt to display it and also it modifies that file to change the image invoking a php.

Currently the php shows only an image but i want it to display multiple ones. The solution i found is creating multiple galleries in the $album_name but in that way i must create one gallery for every picture i want to show.

How could this code be modified so i can use the same album and every image usues a different cover-pic.txt file? So every image should use cover-pic1.txt cover-pic2.txt and so on, so i can use the same gallery for multiple images.

For working you have to create a /images/album1 and put any images inside as long as a cover-pic.txt file inside it.

This is the source Code of the page showing the image:

pic-gal.php

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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>0 && $i<4)
						 {
								 while($i<4)
								 {
									echo "<td>&nbsp;</td>";	
									$i++;
								 }	
								 echo "</tr>";
						}				 
						 											  
		?>	
		</table>		
		<?php
					}//else end
		?>


</body>
</html>

____________________________________

And this is the code for changing the image:


setCoverPic.php:
]

Code: Select all

<?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");
			
?>
Does anyone help on this?
Attachments
picg.rar
This is the working code
(72.4 KiB) Downloaded 45 times
Post Reply