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

  • Home
  • SEARCH
  • 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 8036415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:36:49+00:00 2026-06-05T02:36:49+00:00

I continually make tweaks to my software and upload it to the server. As

  • 0

I continually make tweaks to my software and upload it to the server. As I have customers using my online software all the time, if a PHP file is partially uploaded (let’s say it takes 3 seconds to upload) when a customer clicks a link (say at the 1 second mark) they get an error because the file is still uploading…

Parse error: syntax error, unexpected $end in /inc/functions.php on line 475

As I’m in Australia, our internet… well… “isn’t very fast” is a nice way of putting it.

Are there any techniques used when uploading files so it does not cause errors for customers using the software?

Only thing I can thing of is uploading files to say another directory then running a PHP script that copies the files across super fast… But is there better solutions?

FINAL CODE

Thanks to Greg below I was able to figure out the best way to do things. Thought I’d share my final code. It’s a bit rough but does the trick… Hopefully it helps someone

<?php

// root path
define('ABSPATH', dirname(__FILE__) . '/');

// messages
$GLOBALS['copied'] = array();
$GLOBALS['failed'] = array();
$GLOBALS['folders'] = array();

// you have to submit the form (added security)
if (isset($_POST['copy'])) {

    $GLOBALS['devuploads_folder'] = '_devuploads';

    function find_files($dir) {
        if ($dh = opendir(ABSPATH . $dir)) {
            while (($file = readdir($dh)) !== false) {

                // ignore files
                if ($file === '.' || $file === '..')
                    continue;

                // delete temporary files (optional)
                if ($file == '.DS_Store') {
                    unlink(ABSPATH . $dir . $file);
                    continue;
                }

                // determine paths                  
                $live_path = str_replace($GLOBALS['devuploads_folder'] . '/', '', $dir . $file);                
                $dev_file = $dir . $file;                   
                $live_file = $live_path;
                $dev_file_path = ABSPATH . $dir . $file;                    
                $live_file_path = ABSPATH . $live_path;

                // it's a file
                if (is_file(ABSPATH . $dir . $file)) {  

                    // check if the file has been updated or it's a brand newy
                    $updated_file = $new_file = false;
                    if (file_exists($live_file_path)) {                                 
                        $dev_file_modified = filemtime($dev_file_path);     
                        $live_file_modified = filemtime($live_file_path);                                               
                        if ($dev_file_modified > $live_file_modified)
                            $updated_file = true;                       
                    } else {
                        $new_file = true;
                    }

                    // move the file
                    if ($updated_file || $new_file) {
                        if (copy($dev_file_path, $dev_file_path . '.bak')) {
                            if (rename($dev_file_path . '.bak', $live_file_path))
                                if ($new_file)
                                    $GLOBALS['copied'][] = '<strong>New File:</strong> ' . $dev_file . ' moved to ' . $live_file;   
                                else
                                    $GLOBALS['copied'][] = $dev_file . ' moved to ' . $live_file;   
                            else
                                $GLOBALS['failed'][] = '<strong>Rename failed:</strong> ' . $dev_file . ' to ' . $live_file;
                        } else {
                            $GLOBALS['failed'][] = '<strong>Copy failed:</strong> ' . $dev_file . ' to ' . $dev_file . '.bak';
                        }
                    }

                // it's a folder
                } else if (is_dir(ABSPATH . $dir . $file)) {

                    // create new folder if it doesn't exist
                    if (!is_dir($live_file_path)) {
                        $GLOBALS['folders'][] = '<strong>Created:</strong> ' . $live_file;  
                        mkdir($live_file_path, 0755);   
                    }

                    // keep digging
                    find_files($dir . $file . '/');

                }

            }
            closedir($dh);
        }
    }

    find_files($GLOBALS['devuploads_folder'] . '/');

}

?>
<!DOCTYPE HTML>
<html>
<head>
    <title>Copy Changes</title>
    <style type="text/css">
    h1 {
        font: normal 20px Arial, Helvetica, sans-serif;
        line-height: 24px;
        }
    p, li {
        font: normal 14px Arial, Helvetica, sans-serif;
        line-height: 20px;
        }
    </style>
</head> 
<body>

<?php   
if (!empty($GLOBALS['failed'])) {
    echo '<h1>Errors</h1>';
    echo '<ul>';
    foreach($GLOBALS['failed'] AS $message) {
        echo '<li>' . $message . '</li>';
    }
    echo '</ul>';
}

if (!empty($GLOBALS['folders'])) {
    echo '<h1>New Folders</h1>';
    echo '<ul>';
    foreach($GLOBALS['folders'] AS $message) {
        echo '<li>' . $message . '</li>';
    }
    echo '</ul>';
}

if (!empty($GLOBALS['copied'])) {
    echo '<h1>Copied</h1>';
    echo '<ul>';
    foreach($GLOBALS['copied'] AS $message) {
        echo '<li>' . $message . '</li>';
    }
    echo '</ul>';
}

if (empty($GLOBALS['failed']) && empty($GLOBALS['folders']) && empty($GLOBALS['copied']))
    echo '<p>No updates made.</p>';
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="copy" value="1" />
<p><input type="submit" value="Copy Files" /></p>
</form>

</body>
</html>
  • 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-05T02:36:51+00:00Added an answer on June 5, 2026 at 2:36 am

    If your server is Linux (or other Unix variant), then the mv command is atomic and can do this sort of instantaneous update. First copy the file to a temporary name (like file.php.new), and then log in to the server and

    mv file.php.new file.php
    

    (this works even if file.php exists, it will be replaced by the new one).

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

Sidebar

Related Questions

One thing I have continually found very confusing about using an object database like
I have a GridView which is continually rebound using a timer and is within
I'm trying to make an SSL call using HTTPWebRequest and its continually failing saying
This is my most confused aspect that I continually have to ask people about.
I have these two data structures that I continually find myself choosing between when
I have an English language forum site written in perl that is continually bombarded
I'm trying to make a simple program that continually displays and updates a label
I want to make an app that knows the last time the iPhone moved
I am trying to make a simple client-server chat program. On the client side
I come up against this all the time, and I'm never sure which way

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.