Jump to content

onoffpaul

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

onoffpaul's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, I am having a problem with uploading files .jpeg extensions to a PHP/Mysql gallery. The .jpg extension work but not the .jpeg extension. To rectify the problem I tried first to replace the reference to the .jpg extension to .jpeg in my 'functions.php' file to see if that would work. However, the result of that was that the script uploaded the image with the file extension '.jjpeg' (yes, thats a double 'j'). Below is the functions.php file BEFORE I tried the above. Thanks a mil, Paul function uploadImage($inputName, $uploadDir) { $image = $_FILES[$inputName]; $imagePath = ''; $thumbnailPath = ''; // if a file is given if (trim($image['tmp_name']) != '') { $ext = substr(strrchr($image['name'], "."), 1); // generate a random new file name to avoid name conflict // then save the image under the new file name $imagePath = md5(rand() * time()) . ".$ext"; $result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath); if ($result) { // create thumbnail $thumbnailPath = md5(rand() * time()) . ".$ext"; $result = createThumbnail($uploadDir . $imagePath, $uploadDir . 'thumbnail/' . $thumbnailPath, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT); // create thumbnail failed, delete the image if (!$result) { unlink($uploadDir . $imagePath); $imagePath = $thumbnailPath = ''; } else { $thumbnailPath = $result; } } else { // the image cannot be uploaded $imagePath = $thumbnailPath = ''; } } return array('image' => $imagePath, 'thumbnail' => $thumbnailPath); } /* Create a thumbnail of $srcFile and save it to $destFile. The thumbnail will be $width pixels. */ function createThumbnail($srcFile, $destFile, $width, $height, $quality = 75) { $thumbnail = ''; if (file_exists($srcFile) && isset($destFile)) { $size = getimagesize($srcFile); $w = number_format($width, 0, ',', ''); $h = number_format($height, 0, ',', ''); $thumbnail = copyImage($srcFile, $destFile, $w, $h, $quality); } // return the thumbnail file name on sucess or blank on fail return basename($thumbnail); } //Function to create the album thumbnails function createThumbnail2($srcFile, $destFile, $width, $height, $quality = 75) { $thumbnail = ''; if (file_exists($srcFile) && isset($destFile)) { $size = getimagesize($srcFile); $w = number_format($width, 0, ',', ''); $h = number_format($height, 0, ',', ''); $thumbnail = copyImage($srcFile, $destFile, $w, $h, $quality); } // return the thumbnail file name on sucess or blank on fail return basename($thumbnail); } /* Copy an image to a destination file. The destination image size will be $w X $h pixels */ function copyImage($srcFile, $destFile, $w, $h, $quality = 75) { $tmpSrc = pathinfo(strtolower($srcFile)); $tmpDest = pathinfo(strtolower($destFile)); $size = getimagesize($srcFile); if ($tmpDest['extension'] == "gif" || $tmpDest['extension'] == "jpg") { $destFile = substr_replace($destFile, 'jpg', -3); $dest = imagecreatetruecolor($w, $h); //imageantialias($dest, TRUE); } elseif ($tmpDest['extension'] == "png") { $dest = imagecreatetruecolor($w, $h); //imageantialias($dest, TRUE); } else { return false; } switch($size[2]) { case 1: //GIF $src = imagecreatefromgif($srcFile); break; case 2: //JPEG $src = imagecreatefromjpeg($srcFile); break; case 3: //PNG $src = imagecreatefrompng($srcFile); break; default: return false; break; } imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]); switch($size[2]) { case 1: case 2: imagejpeg($dest,$destFile, $quality); break; case 3: imagepng($dest,$destFile); } return $destFile; }
  2. Hi, I am a relative newbie to PHP. I am currently building a photo gallery for an events website and I have most of the backend finished. I am having a very basic problem with the homepage of the gallery. Basically, the way I am designing is in a table with 2 columns; - a column with a cover image for each album - a column with thumbnails from that album I want to display on the albums/image like this in rows. This is where I am having the problem... I have the album cover image working fine but for some reason the same images are showing up for each album. I'm pretty sure it has something to do with a 'while' loop and the album id. Below is the PHP code I know this a basic problem, but help would be MUCH appreciated!! Thanks, Paul PHP Code: <table border="0" cellpadding="5" cellspacing="0"> <? $db_cnx = mysql_connect ('localhost', 'user', 'password'); $db_select = mysql_query ('USE gallery'); $sql = "SELECT al_id, al_name, al_image, COUNT(im_album_id) AS al_numimage FROM tbl_album al LEFT JOIN tbl_image im ON al.al_id = im.im_album_id GROUP by al_id ORDER BY al_name"; $result = mysql_query($sql) or die('Error, list album failed. ' . mysql_error()); /*while ($get_id = mysql_fetch_assoc($result)) { echo $get_id['al_id'];}*/ while ($get_id = mysql_fetch_assoc($result)) { $albumid = $get_id['al_id'];} $result = mysql_query($sql) or die('Error, list album failed. ' . mysql_error()); while ($row = mysql_fetch_assoc($result)) { /*$numImages = $row['al_numimage'] > 1 ? $row['al_numimage'] . ' images' : $row['al_numimage'] . ' image';*/ echo /*ECHO THE ALBUMS*/ '<tr>'. '<td>'. '<a href="index.php?page=list-image&album=' . $row['al_id'] . '">' . '<img src="viewImage.php?type=album&name=' . $row['al_image'] . '" border="0">' . '<br>' . $row['al_name'] . '</a><br />' . $numImages . '</td>'; /*START GETTING THE IMAGES*/ $query2 = "SELECT im_id, im_title, im_thumbnail FROM tbl_image WHERE im_album_id = '$albumid' ORDER BY im_title"; $result2 = mysql_query($query2) or die('Error, list image failed. ' . mysql_error()); while ($row2 = mysql_fetch_assoc($result2)) { echo /*ECHO THE IMAGES*/ '<td>'. '<a href="?page=image-detail&album=' . $albumId . '&image=' . $row2['im_id'] . '">' . '<img src="viewImage.php?type=glthumbnail&name=' . $row2['im_thumbnail'] . '" border="0">' . '</td>'; } echo '</tr>'; } ?> </table>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.