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 8236619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:11:29+00:00 2026-06-07T19:11:29+00:00

I’m uploading files (images) to my file structure using Uploadify, then catching each file,

  • 0

I’m uploading files (images) to my file structure using Uploadify, then catching each file, giving it a random number as a file name, resizing it using the excellent SimpleImage script into Large, Medium, and Small sizes, saving those to the directory, discarding the original image, and writing the file details (the random number, the original name, the album ID, etc) to the database for access later.

All of this is working without a hitch escept the writing to the DB part. I find only the first file’s information is passed to the DB, and with an incorrect number as the filename.

In short, how can I write EACH file’s information to the Database (correctly), when using Uploadify on multiple images?

My current script:

*note: AlbumID is set dynamically by the user and posted as filedata to uploadify.

require_once '../../functions.php';
require_once '../../conn.php';

//defaults
$uploadify_path = '/contents/uploads/gallery/';
$albumID = $_POST['AlbumID'];

//Define a destination
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_POST['path']; // Relative to the root

if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetFile = $targetPath . $_FILES['Filedata']['name'];
include($_SERVER['DOCUMENT_ROOT'].'/includes/SimpleImage.php');

// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);

if (in_array($fileParts['extension'],$fileTypes)) {
    $ran = $albumID.RandNumber(10);
    $location=$targetPath.$ran;

    $LegacyName = $fileParts['filename'];
    $FileExt = $fileParts['extension'];

    if(is_numeric($albumID)) {
        $q = "INSERT INTO gallery_meta (AlbumID, FileName, LegacyName, FileExt, IsDefault, Public)
                VALUES ('$albumID','$ran','$LegacyName','$FileExt','0','1')";
        $r= mysql_query($q);
        mysql_free_result($r);
    }

    move_uploaded_file($tempFile,$targetFile);

    list($width, $height, $type, $attr) = getimagesize($targetFile);

    $image = new SimpleImage();
    $image->load($targetFile);

    if( $height >= 901 ) {
        $image->resizeToHeight(900);
        $image->save($location.'-lrg.'.$FileExt);
        $image->resizeToHeight(550);
        $image->save($location.'-med.'.$FileExt);
        $image->resizeToHeight(200);
        $image->save($location.'-sm.'.$FileExt);
        unlink($targetFile);
    }
    elseif(( $height  >= 551 )&&( $height <= 900 )) {
        $image->save($location.'-lrg.'.$FileExt);
        $image->resizeToHeight(550);
        $image->save($location.'-med.'.$FileExt);
        $image->resizeToHeight(200);
        $image->save($location.'-sm.'.$FileExt);
        unlink($targetFile);
    }
    elseif(( $height >= 201 )&&( $height <= 550 )) {
        $image->save($location.'-lrg.'.$FileExt);
        $image->save($location.'-med.'.$FileExt);
        $image->resizeToHeight(200);
        $image->save($location.'-sm.'.$FileExt);
        unlink($targetFile);
    }
    if( $height  <= 200 ) {
        $image->save($location.'-lrg.'.$FileExt);
        $image->save($location.'-med.'.$FileExt);
        $image->save($location.'-sm.'.$FileExt);
        unlink($targetFile);
    }

    echo '1';
} else {
    echo 'Invalid file type.';
}
}
  • 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-07T19:11:30+00:00Added an answer on June 7, 2026 at 7:11 pm

    add an auto incrementing key to the table, and change albumID into a BIGINT if you’re sure your values aren’t going to overflow the size of BIGINT, but if they are I recommend you save the “AlbumId” as a VARCHAR(30) instead, since it’s more of a name than an actual number key, especially since it looks like it can be an arbitrary length.

    I also think that instead of a random number at the end, you should be appending the current timestamp using time() so that you don’t create the potential of collisions like a system with random numbers & user input will.

    Also incidentally, $_POST['albumId'], by being direct user input.. is leaving your database open to a MySQL Injection attack.

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

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.