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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:43:33+00:00 2026-05-21T03:43:33+00:00

I am working on a piece of code that I am wanting to spice

  • 0

I am working on a piece of code that I am wanting to “spice” up with jQuery but I can’t think of a way to actually make it work. I am sure its simple, I just need a little advice to get me going.

I am wanting to create a piece of code that makes an Ajax request out to start a big loop that will download files and then upload them to an S3 bucket of mine. The place where I am stuck is I am wanting to send back a request back to the browser everytime a file is uploaded and output a string of text to the screen upon completion.

I don’t have any of the frontend code working… just trying to get my head wrapped around the logic first… any ideas?

PHP Backend Code:

<?php
    public function photos($city) {
        if(isset($city))
            $this->city_name = "{$city}";

        // grab data array from Dropbox folder
        $postcard_assets = $this->conn->getPostcardDirContent("{$this->city_name}", "Photos", TRUE);
        $data = array();

        foreach($postcard_assets['contents'] as $asset) {
            //only grab contents in root folder... do not traverse into sub folders && make sure the folder is not empty
            if(!$asset['is_dir'] && $asset['bytes'] > 0) {
                // get information on file
                $file = pathinfo($asset['path']);

                // download file from Dropbox
                $original_file = $this->conn->downloadFile(str_replace(" ", "%20", $asset['path']));

                // create file name
                $file_name = $this->cleanFileName($file['basename']);

                // write photo to TMP_DIR ("/tmp/photos/") for manipulation
                $fh = fopen(self::TMP_DIR . $file_name, 'w');
                fwrite($fh, $original_file);
                fclose($fh);

                // Resize photo
                $this->resize_photo($file_name);

                // hash file name
                $raw_file = sha1($file_name);
                // create S3 hashed name
                $s3_file_name = "1_{$raw_file}.{$file['extension']}";
                // Upload manipulated file to S3
                $this->s3->putObject($s3_file_name, file_get_contents(self::TMP_DIR . $file_name), $this->photo_s3_bucket, 'public-read');

                // check to see if file exists in S3 bucket
                $s3_check = $this->s3->getObjectInfo($s3_file_name, $this->photo_s3_bucket);

                // if the file uploaded successully to S3, load into DB
                if($s3_check['content-length'] > 0) {
                    $data['src'] = $s3_file_name;
                    $data['width'] = $this->width;
                    $data['height'] = $this->height;
                    Photo::create_postcard_photo($data, "{$this->city_name}");
                    // Now that the photo has been uploaded to S3 and saved in the DB, remove local file for cleanup
                    unlink(self::TMP_DIR . $file_name);
                    echo "{$file_name} uploaded to S3 and resized!<br />";
                }
            }
        }
        // after loop is complete, kill script or nasty PHP header warnings will appear
        exit();
    }
?>
  • 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-05-21T03:43:34+00:00Added an answer on May 21, 2026 at 3:43 am

    The main problem is that with PHP, the output is buffered so it won’t return a line at a time. You can try and force the flush but it’s not always reliable.

    You could add an entry to the DB for each file that is exchanged and create a seperate API to get the details of what has completed.

    Generally, Jquery will wait till the request has finished before it allows you to manipulate data from a HTTP request.

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

Sidebar

Related Questions

I've been working on this small piece of code that seems trivial but still,
I have this piece of code that is working but is kind of cumbersome.
I have a piece of code that is working fine in IE, but it
I'm working on a piece of code that I inherited and am trying to
The following piece of code is working on Android devices and iPhone simulator but
I'm trying to create a piece of code but cannot get it working. The
I really can't understand how the below piece of code is working... options.each {
I'm working on a piece of software that would work well with an iTunes
I'm currently working on a piece of code that quite simply uses a boolean
I'm working on a piece of code that interacts with Resources (Executables) however i'm

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.