Okay, I have been trying to make a script that will upload up to 10 JPEGs to a specified folder and create thumbs of them and upload them too. I then want the image's filename to be inserted into a DB. Here's the code I have come up with. Nothing is done when I run it. Nothing is inserted into , nothing is uploaded.
<?
// form not yet submitted
// display initial form
if (!$submit)
{
?>
<table cellspacing="5" cellpadding="5">
<form action="<? echo $PHP_SELF; ?>" method="POST">
<tr>
<td valign="top"><b><font size="-1">Title</font></b></td>
<td><input size="50" maxlength="250" type="text" name="title"></td>
</tr>
<tr>
<td valign="top"><b><font size="-1">Pic 1</font></b></td>
<td><input type="file" name="photo[]"></td>
</tr><tr>
<tr>
<td valign="top"><b><font size="-1">Pic 2</font></b></td>
<td><input type="file" name="photo[]"></td>
</tr><tr>
<tr>
<td valign="top"><b><font size="-1">Pic 3</font></b></td>
<td><input type="file" name="photo[]"></td>
</tr><tr>
<tr>
<td valign="top"><b><font size="-1">Pic 4</font></b></td>
<td><input type="file" name="photo[]"></td>
</tr><tr>
<tr>
<td valign="top"><b><font size="-1">Pic 5</font></b></td>
<td><input type="file" name="photo[]"></td>
</tr><tr>
<tr>
<td valign="top"><b><font size="-1">Pic 6</font></b></td>
<td><input type="file" name="photo[]"></td>
</tr><tr>
<tr>
<td valign="top"><b><font size="-1">Pic 7</font></b></td>
<td><input type="file" name="photo[]"></td>
</tr><tr>
<tr>
<td valign="top"><b><font size="-1">Pic 8</font></b></td>
<td><input type="file" name="photo[]"></td>
</tr><tr>
<tr>
<td valign="top"><b><font size="-1">Pic 9</font></b></td>
<td><input type="file" name="photo[]"></td>
</tr><tr>
<tr>
<td valign="top"><b><font size="-1">Pic 10</font></b></td>
<td><input type="file" name="photo[]"></td>
</tr><tr>
<td colspan=2><input type="Submit" name="submit" value="Add"></td>
</tr>
</form>
</table>
<?
}
else
{
// includes
include("conf.php");
include("functions.php");
// set up error list array
$errorList = array();
$count = 0;
// validate text input fields
if (!$title) { $errorList[$count] = "Invalid entry: Title"; $count++; }
// check for errors
// if none found...
if (sizeof($errorList) == 0)
{
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query
if( $photo[ $i ] != "" && $photo[ $i ] != "none" )
{
if( $photo_size[ $i ] > 500000 ) error( "Invalid image size" );
if( $photo_type[ $i ] == "image/pjpeg" || $photo_type[ $i ] == "image/jpeg" )
$newphoto[] = $photo[ $i ];
else
error( "Invalid image type, JPEG only!" );
}
$newid = mysql_insert_id();
for( $i = 0; $i < count( $newphoto ); $i++ )
{
mysql_query( "INSERT INTO photo ( imgurl ) VALUES ( $filename )" ) or error( mysql_error() );
$photoid = mysql_insert_id();
copy( $newphoto[ $i ], "cms/{$photoid}.jpg" );
makeThumb( $newphoto[ $i ], "cms/thumb/{$photoid}.jpg" );
unlink( $newphoto[ $i ] );
}
// close database connection
mysql_close($connection);
}
else
{
// errors found
// print as list
echo "<font size=-1>The following errors were encountered: <br>";
echo "<ul>";
for ($x=0; $x<sizeof($errorList); $x++)
{
echo "<li>$errorList[$x]";
}
echo "</ul></font>";
}
?>
this is the fucntions.php file:
<?
// format MySQL DATETIME value into a more readable string
function formatDate($val)
{
$arr = explode("-", $val);
return date("d M Y", mktime(0,0,0, $arr[1], $arr[2], $arr[0]));
}
function makeThumb( $scrFile, $dstFile, $dstW=120, $dstH=100 )
{
$im = ImageCreateFromJPEG( $scrFile );
$srcW = ImageSX( $im );
$srcH = ImageSY( $im );
$ni = ImageCreate( $dstW, $dstH );
ImageCopyResized( $ni, $im, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH );
ImageJPEG( $ni, $dstFile );
}
?>
could someone please help me out?
help is appreciated highly,
mike