Link to home
Start Free TrialLog in
Avatar of ITNC
ITNCFlag for United States of America

asked on

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:

<?php
$upload_directory=dirname(__FILE__).'/uploads/';
//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
            move_uploaded_file($_FILES['my_file']['tmp_name'],
                $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.
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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  http://php.net/manual/en/features.file-upload.php

cURL does provide some info about file uploads but I've only used it on the command line.  http://php.net/manual/en/book.curl.php
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ITNC

ASKER

gr8gonzo,

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?
Avatar of ITNC

ASKER

Also can you provide examples for the second point in your first post about the server extensions?
Avatar of ITNC

ASKER

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.