PHP Curl POST\Upload File and write in real time.

So currently when I use my script to upload a file to my remote server it copies the file to the desired location after the upload has completed. I need to modify the script to write the file in real time to the destination as it is being uploaded. Here is the remote script that accepts the curl post and writes the file as it currently stands:

//check if form submitted
if (isset($_POST['upload'])) {
    if (!empty($_FILES['my_file'])) {
        //check for image submitted
        if ($_FILES['my_file']['error'] > 0) {
            // check for error re file
            echo "Error: " . $_FILES["my_file"]["error"] ;
        } else {
            //move temp file to our server
                $upload_directory . $_FILES['my_file']['name']);
            echo 'Uploaded File.';
    } else {
        die('File not uploaded.');
        // exit script

My ultimate goal here is to be able to check the file size of the file being uploaded as it is being uploaded from the remote end.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
I think you will find that it just doesn't work that way.  A file upload thru HTTP actually goes to a temp buffer on the web server and not the file system.  The web server makes the info available to PHP so you can move the file.  You would have be using SMB or some similar protocol that deals directly with the file system to upload it directly to the destination location.

PHP File upload info

cURL does provide some info about file uploads but I've only used it on the command line.
1. You cannot upload directly to the destination file without trying to re-invent the wheel. However, to do that would result in a HUGE security hazard, because the end user could specify the destination location, and a malicious user could use this to essentially send data wherever he/she wanted. They could upload their own attack scripts and execute them. LOTS of things that could go wrong there.

The purpose of temp files is that you can check the data and control the final location from a trusted, server-side bit of code.

2. There are web server extensions/modules that have been built for the specific purpose of reporting the file size and status of file uploads. It's far better to use one of those.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You could also check out:

...but it only works in certain environments, so you'd have to try it out to see if it works for you.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

ITNCAuthor Commented:

That last link you posted looks promising. I am still looking into it but right now I am having issues grasping how I can get that array of info from the remote end. Do you maybe have an example I could look at?
ITNCAuthor Commented:
Also can you provide examples for the second point in your first post about the server extensions?
ITNCAuthor Commented:
I have decided to try using APC_UPLOAD_PROGRESS. I have installed the extension and enabled the necessary options. I am now trying to throw together a test setup now. If you have any further information on this please feel free to share.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.