Jump to content

jillianmarie

New Members
  • Posts

    1
  • Joined

  • Last visited

jillianmarie's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey all, hoping to get this code solved. I am building an image gallery for a client's website and wanted a way for the client to upload their own images from the back end and shows up on the website page for the pictures. I am using color box as the lightbox feature for the photos and on the webpage thumbnails are displayed in rows. In the backend, I have the upload page and here is my form: <form name="form" action="../uploader.php" method="POST" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="uploaded_file" id="uploaded_file"> <input type="hidden" name="MAX_FILE_SIZE" value="10485760" /><br /> <input type="hidden" name="image_type" value="" /><br /> <input type="submit" name="submit" value="Submit"> <input type="hidden" name="MM_insert" value="form" /> </form> From the admin upload page, the client can upload their image and it will save it into the "image/uploads/" folder. Here is the uploader.php script: <?php //Сheck that we have a file if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) { //Check if the file is JPEG image and it's size is less than 1.4MB $filename = basename($_FILES['uploaded_file']['name']); $ext = substr($filename, strrpos($filename, '.') + 1); if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && ($_FILES["uploaded_file"]["size"] < 10485760)) { //Determine the path to which we want to save this file $newname = dirname(__FILE__).'/images/uploads/'.$filename; //Check if the file with the same name is already exists on the server if (!file_exists($newname)) { //Attempt to move the uploaded file to it's new place if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) { echo "Upload Complete! "; } else { echo "Error: A problem occurred during file upload!"; } } else { echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists"; } } else { echo "Error: File too big to upload"; } } else { echo "Error: No file uploaded"; } ?> Now the website page will display all the images in the "images/uploads" folder and will update itself when new photos are uploaded. Here is the gallery code from the website: <div class="gallery"> <?php /* function: returns files from dir */ function get_files($images_dir,$exts = array('jpg')) { $files = array(); if($handle = opendir($images_dir)) { while(false !== ($file = readdir($handle))) { $extension = strtolower(get_file_extension($file)); if($extension && in_array($extension,$exts)) { $files[] = $file; } } closedir($handle); } return $files; } /* function: returns a file's extension */ function get_file_extension($file_name) { return substr(strrchr($file_name,'.'),1); } /** settings **/ $images_dir = 'images/uploads/'; $images_per_row = 5; /** generate photo gallery **/ $image_files = get_files($images_dir); if(count($image_files)) { $index = 0; foreach($image_files as $index=>$file) { $index++; echo '<a href="',$images_dir.$file,'" class="photo-link group1" rel="uploads"><img src="timthumb.php?src=',$images_dir.$file,'&h=150&w=150" /></a>'; if($index % $images_per_row == 0) { echo '<div class="clear"></div>'; } } echo '<div class="clear"></div>'; } else { echo '<p>There are no images in this gallery.</p>'; } ?> </div> With the help from timthumb.php and timthumb-config.php I am able to produce the thumbnails for the website. Once clicked, brings up the colorbox feature for the image slideshow. For some reason, this code only can use image sizes under 1500px. How can I upload a bigger image and resize it to save itself into the "images/uploads/" folder to be under 1500px? Please look at my codes and let me know where and what code I need to produce the resized image. Thanks!
×
×
  • 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.