I've been trying to make a photo gallery, so far with the upload screen, it comes up saying it worked, when I check for errors it comes out with nothing and yet it doesn't add anything to MySQL. Help?
<?php
include 'conne开发者_开发知识库ct.php';
$photo_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg',
'image/gif' => 'gif',
'image/bmp' => 'bmp',
'image/x-png' => 'png'
);
$pics=$_FILES['filename'];
$caps=$_POST['captions'];
$cout=0;
while($cout <= count($pics))
{
if(isset($pics[$cout]) && $pics[$cout] > 0)
{
if(!array_key_exists($pics['type'][$cout], $photo_types))
{
$finals .= 'File ' . ($cout + 1) . ' is not a photo<br />';
}
else
{
$typo=$pics['type'][$cout];
$extnz=$photo_types[$filetype];
$filename="$new_id.$extension";
mysql_query("
INSERT INTO photos (
filename,
caption,
album
) VALUES (
'" . $filename . "',
'" . $caps[$cout] . "',
'" . $_POST['album'] . "'
)
") or die(mysql_error());
mysql_commit($connection);
copy($pics['tmp_name'][$cout],$image_dir . '/' . $filename);
$size=GetImageSize('photos/' . $filename);
if ($size[0]>$size[1])
{
$tw=100;
$th=(int)(100*$size[1]/$size[0]);
}
else
{
$tw=(int)(100*$size[0]/$size[1]);
$th=100;
}
$im="C:\Program Files (x86)\ImageMagick-6.7.0-Q16";
exec("$im/convert -geometry " . "{$tw}x{$th} " . "$image_dir/$filename photos/tb_$filename");
}
}
$cout++;
}
echo "worked!";
mysql_close($connection);
?>
You need to use COMMIT
to actually commit the transaction to the database.
I figured it out, the problem was I was doing
if (isset($pics[$cout]))
so to fix this I did
if (isset($pics['name'][$cout]))
精彩评论