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.
ITNCAsked:
Who is Participating?
 
gr8gonzoConsultantCommented:
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.
0
 
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  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
0
 
gr8gonzoConsultantCommented:
You could also check out:
http://php.net/manual/en/session.upload-progress.php

...but it only works in certain environments, so you'd have to try it out to see if it works for you.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
ITNCAuthor Commented:
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?
0
 
ITNCAuthor Commented:
Also can you provide examples for the second point in your first post about the server extensions?
0
 
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.