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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:31:47+00:00 2026-06-06T08:31:47+00:00

I need some help with PHP Class. I have limited knowledge about how it

  • 0

I need some help with PHP Class. I have limited knowledge about how it works, and am trying to discover more about it. In the mean time I have an issue where I need to grab the variable after it runs through these functions within a class.

protected function upcount_name_callback($matches) {
        $index = isset($matches[1]) ? intval($matches[1]) + 1 : 1;
        $ext = isset($matches[2]) ? $matches[2] : '';
        return ' ('.$index.')'.$ext;
    }

    protected function upcount_name($name) {
        return preg_replace_callback(
            '/(?:(?: \(([\d]+)\))?(\.[^.]+))?$/',
            array($this, 'upcount_name_callback'),
            $name,
            1
        );
    }

I need to retrieve this variable in the following JS statement and send to my INSERT php file.

$('#albumBack.fileupload').bind('fileuploaddone',function(e,data) {

    //Loop through each page and return object and write to DB
    $.each(data.files, function (index, file) {
        var filename = file.name;
        $.ajax({ 
            type: "POST",
            url: "../albumUploader/queries/albumPages.php",
            data: {file: filename}
        });
    });
});

The filename that I am getting currently is the original name, not the appended name.
Thanks for any help on this.

albumPages.php

//Variables for gallerimage table
    $originalName = $_POST['file'];
    $clientRef = $_SESSION['clientRef'];
    $galleryID = $_SESSION['newGalleryId'];
    $galleryLayout = $_SESSION['layoutID'];
    $imageID = rand();

    //Find the sort# for the gallery
    $qSortOrder = mysql_query("SELECT MAX(sort) AS sortOrder
                                    ,id
                                    ,clientRef
                                    ,galleryId
                                    FROM galleryimage
                                    WHERE galleryId='{$galleryID}' 
                                    AND clientRef= '{$clientRef}'
                                    ");
    $fsortOrder = mysql_fetch_array($qSortOrder);
    //Latest revision
    $orderNumber = $fsortOrder['sortOrder'];
    $order = $orderNumber + 1;

    $query = "INSERT INTO galleryimage 
            (
                galleryId
                ,image
                ,OrgImageName
                ,clientRef
                ,sort
                ,layout
            ) VALUES (
                '{$galleryID}'
                ,'{$imageID}'
                ,'{$originalName}'
                ,'{$clientRef}'
                ,'{$order}'
                ,'{$galleryLayout}'
            )";
    $return = mysql_query($query);

$originalName is the $variable that I need to define as img.jpg, $img(1).jpg etc. I am just POSTING file, which ends up being the original selected file from the input.

This is the form that selects the file(s).

<form class="fileupload" id="albumBack" action="../js/jQuery-file-upload/server/php/" method="POST" enctype="multipart/form-data" >
                <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
                <div class="row fileupload-buttonbar">
                        <span class="btn btn-success fileinput-button">
                            <span>Choose Back</span>
                            <input type="file" name="files[]">
                        </span>
                    </div>
  • 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-06T08:31:50+00:00Added an answer on June 6, 2026 at 8:31 am

    Without knowing the contents of albumBack.php, it’s hard to ascertain exactly the behavior you’ll see. But lets assume that albumBack.php calls upcount_name($name) at some point.

    What happens then is that preg_replace_callback is called. This function specifically takes a string and a regex expression, along with an additional ‘callback’ function. It runs the regex on the string and gets a set of matches which is then passed to the callback function. Callbacks allow you to ‘inject’ behavior in a flexible manner: in this case, the callback is a way of defining what the replacement string should be for each regex match.

    The upcount_name_callback function is what is being called here. To understand what it does you have to understand the regex expression. This is a bit complicated, but essentially it’s looking for some number (the [\d]+ part), a . followed by an end of line. upcount_name_callback takes this as a number, which it increments and an extension, which it returns as-is if it exists, and as an empty string if not.

    The upshot is that this appears to change ‘blah.jpg’ to ‘blah1.jpg’ and ‘blah1.jpg’ to ‘blah2.jpg’. However, it looks like if the name you’re getting back is the same, it’s not actually being executed. You would need to post the calling lines of code from albumBack.php to confirm this.

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

Sidebar

Related Questions

Need some help with inclusion of outside variables. I have this file lang.class.php class
( First time programming in PHP. Had some help. Need a bit more. )
Need some help about with Memcache. I have created a class and want to
I'm a noob with mysql and php, and need some help :) I have
I need some help, I have created this function and it works fine, but
I need some help to get this to work. It works, but i have
I need some help with some PHP and MySQL code. At the moment I
I need some help with a small php problem. But i dont know how
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some help with Activerecord Querying in a has_many :through association. Model: Job class

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.