Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8302613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:20:00+00:00 2026-06-08T17:20:00+00:00

I’m using PHP/MySQL to upload multiple images for photo album. The information associated with

  • 0

I’m using PHP/MySQL to upload multiple images for photo album. The information associated with the images (filenames, extensions, descriptions etc.) is stored in database as base64 encoded data. I’m also able to edit the album images. My problem now is that I also want to create thumbnails for each of the images when uploading them on insert and edit mode and also store the information for the thumbnails the same way I do for the images (base64 encoded). What’s the best way to do that? Thanks
Here’s my code:

<?php

//Code for the editing albums in database   
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit') {

        //select photo album and get photos and descriptions to be merged with new.
        $album_id           = $_REQUEST['album_id'];    
        $old_photos         = null;
        $old_descriptions   = null;

        $getAlbumQ = mysql_query("select * from albums where id='$album_id'");

        while ($old_album = mysql_fetch_array($getAlbumQ)) {
            $old_photos         = unserialize(base64_decode($old_album['photos']));
            $old_descriptions   = unserialize(base64_decode($old_album['descriptions']));
            $old_timestamp=$old_album['timestamp'];
        }

        if (isset($_POST['album_name']) && isset($_POST['desc'])) {
            $name       = mysql_real_escape_string($_POST['album_name']);
            $desc       = mysql_real_escape_string($_POST['desc']);
            $idesc      = array();
            $target_path = "/uploads/albums/";



            foreach ($_FILES as $key => $value) {
                 foreach ($value as $k => $v) {
                         if ($k === 'name' && $v !== '') {
                             break;
                         } else {
                             unset($_FILES[$key]);
                         }

                    }

                //first upload photos
                $path = $target_path . basename($old_timestamp.$value['name']); 
                if(move_uploaded_file($value['tmp_name'], $path)) {

                  $hasUpload = true;

                }   

            }


            for ($j = 1; $j < 21; $j++) {
                    $img_index  = $j;
                    $img_desc   = $_POST['desc_' . $img_index];
                    array_push($idesc, $img_desc);

            }


             foreach ($_FILES as $key => $value) {

                    foreach ($value as $k => $v) {
                         if ($k=='name' && $v!='') {
                             break;
                         } else {
                             unset($_FILES[$key]);
                           }
                   }
            }

function merge(&$a, &$b){
     $keys = array_keys($a);
     foreach($keys as $key){
          if(isset($b[$key])){
              if(is_array($a[$key]) and is_array($b[$key])){
                 merge($a[$key],$b[$key]);
              }
              else{
                  $a[$key] = $b[$key];
              }
          }
     }
    $keys = array_keys($b);
    foreach($keys as $key){
        if(!isset($a[$key])){
            $a[$key] = $b[$key];
        }
    }
}

            for ($i = 1; $i < 21; $i++) {

                $file_index     = $i;
                $file_number    = $_POST['image_' . $file_index];

                if($_FILES['image_'.$i]['name']!= ''){

                  $hasUpload = true;

                  $presults         = merge($old_photos, $_FILES);
                  $dresults     = array_merge($old_descriptions, $idesc);

                  $images       = base64_encode(serialize($presults));
                  $descriptions = base64_encode(serialize($dresults));
                  $posted       = date("Y-m-d H:i:s");
                }
                else {
                  $hasUpload = false;

                  $presults         = $old_photos;
                  $dresults     = $idesc;

                  $images       = base64_encode(serialize($presults));
                  $descriptions = base64_encode(serialize($dresults));
                  $posted       = date("Y-m-d H:i:s");
                }
            }

}

    if (mysql_query("update albums set description = '$desc', name = '$name', photos='$images', descriptions='$descriptions' where id='$album_id'")) {
        $hasAlbums = true;
    } else {
        $hasErrors = true;
    }
} else {

    //Code for the inserting albums in database
    if (isset($_POST['album_name'])) {


        if (isset($_POST['album_name']) && isset($_POST['desc'])) {
            $name       = mysql_real_escape_string($_POST['album_name']);
            $desc       = mysql_real_escape_string($_POST['desc']);
            $idesc      = array();
            $timestamp = time();
            $target_path = "/uploads/albums/";


            foreach ($_FILES as $k => $v) {
                //first upload photos
                $path = $target_path . basename($timestamp.$v['name']); 
                if(move_uploaded_file($v['tmp_name'], $path)) {

                    $img_index  = explode('_', $k);
                    $img_index  = $img_index[1];
                    $img_desc   = $_POST['desc_' . $img_index];
                    array_push($idesc, $img_desc);

                    $file_name  = $timestamp.$v['name'];
                    $hasUpload = true;
                }   
            }

            $images         = base64_encode(serialize($_FILES));
            $descriptions   = base64_encode(serialize($idesc));
            $posted         = date("Y-m-d H:i:s");


            $query = mysql_query("
        INSERT INTO albums (description, posted, photos, name, descriptions, timestamp) 
                    VALUES ('$desc', '$posted', '$images', '$name', '$descriptions', '$timestamp')
            ");
        }
    }
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:20:01+00:00Added an answer on June 8, 2026 at 5:20 pm

    I tried a simple thumbnail script found on this tutorial and it worked perfectly: http://net.tutsplus.com/articles/news/how-to-dynamically-create-thumbnails/

    Thanks for your suggestions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Paperclip to handle profile photo uploads in my app. They upload
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.