Hello hoping someone can help me, im fairly new with php and i am looking to make my images ( which i have uploaded from a filename) and mysql, i am looking to make them into smaller images.
I am have found a learning script to help me do so but im not getting very far with it (and i have tried several) and i really need someones help.
This is the thumbnail script
function createGallery( $pathToImages, $pathToThumbs )
{
echo "Creating gallery.html <br />";
$output = "<html>";
$output .= "<head><title>Thumbnails</title></head>";
$output .= "<body>";
$output .= "<table cellspacing=\"0\" cellpadding=\"2\" width=\"500\">";
$output .= "<tr>";
// open the directory
$dir = opendir( $pathToThumbs );
$counter = 0;
// loop through the directory
while (false !== ($fname = readdir($dir)))
{
// strip the . and .. entries out
if ($fname != '' && $fname != '')
{
$output .= "<td valign=\"middle\" align=\"center\"><a href=\"{$pathToImages}{$fname}\">";
$output .= "<img src=\"{$pathToThumbs}{$fname}\" border=\"0\" />";
$output .= "</a></td>";
$counter += 1;
if ( $counter % 4 == 0 ) { $output .= "</tr><tr>"; }
}
}
// close the directory
closedir( $dir );
$output .= "</tr>";
$output .= "</table>";
$output .= "</body>";
$output .= "</html>";
// open the file
$fhandle = fopen( "gallery.html", "w" );
// write the contents of the $output variable to the file
fwrite( $fhandle, $output );
// close the file
fclose( $fhandle );
}
// call createGallery function and pass to it as parameters the path
// to the directory that contains images and the path to the directory
// in which thumbnails will be placed. We are assuming that
// the path will be a relative path working
// both in the filesystem, and through the web for links
createGallery("images/","images/thumbs/");
?>
and this is the code for my start page (start.php)
<form enctype="multipart/form-data" action="add.php" method="POST">
Name: <input type="text" name="name"><br>
Description: <input type="text" name="description"><br>
Price: <input type="text" name="price"><br>
Photo: <input type="file" name="photo"> <br>
<input type="submit" value="add">
</form>
<?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("cars") or die(mysql_error()) ;
include("./class.image.php") ;
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM cars") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
//Outputs the image and other data
Echo "<img src=images/".$info['photo'] ."> <br>";
Echo "<b>Name:</b> ".$info['name'] . "<br> ";
Echo "<b>Description:</b> ".$info['description'] . " <br>";
Echo "<b>Price:</b> ".$info['price'] . " <hr>";
}
and this is the script for my second page add.php
<?php
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$name=$_POST['name'];
$description=$_POST['description'];
$price=$_POST['price'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("cars") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO cars VALUES ('$name', '$description', '$price', '$pic')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
As you can see, i just need help tieing the thumbnail script into my script properly, if someone could just help me out and tell me where i need to change variables and that on my thumbnail script and what to that would be brilliant as im confused in which i need to change and change too. For example does the {$pathtoimages} varriable on the thumbnail need to be changed to the actual path to images as well or just kept like that?
Thankyou very much, any help with this would truly be appreciated as i really am trying to learn