Search code examples
phpjavascriptwordpressapc

Can't move/fine APC Uploaded file


As a bit of a follow up to Javascript form won't submit (to view the code I am using visit that link) I am now encountering a problem that I cannot find the file that has been uploaded.

I have added $files = apc_fetch('files_'.$_POST['APC_UPLOAD_PROGRESS']); to the top of my page and this is the output of print_r($files);

Array
(
    [theFile] => Array
        (
            [name] => tt1.mp4
            [type] => video/mp4
            [tmp_name] => /tmp/php2BEvy7
            [error] => 0
            [size] => 1050290
        )
)

However when I try to run the following code:

if (file_exists($files['theFile']['tmp_name'])) {

    $webinarType = strcmp($files['theFile']['type'], 'video/mp4');

    if($webinarType == 0) {

        $webinarFile = $fileTitle;
        $webinarTempName = $files['theFile']['tmp_name']; 

    } else {

        echo 'Webinar must be .mp4';

    }

} else {

    echo "No File";

}

I get the No File output.

I have ssh'd into the server and the file is not in /tmp/, /path/to/public_html/tmp/ or path/to/file/tmp/ all of which exist.

I have tried to use move_uploaded_file() but as this is executed on all file inputs I can't get the tmp_name dynamically due to my limited knowledge of javascript.

tl;dr version; Where is my file gone and how can I find it?

NOTE; This form did work before the APC intevention and I am running wordpress in case that affects anything.


Solution

  • Fixed this one on my own as well.

    In the progress.php file (found on the other question) I modified the elseif statement with this:

    elseif(($s_progressId = $_POST['APC_UPLOAD_PROGRESS']) || ($s_progressId = $_GET['APC_UPLOAD_PROGRESS']))
    {
        // If the file has finished uploading add content to APC cache
            $realpath = realpath($PHP_SELF); 
            $uploaddir = $realpath . '/tmp/';
            foreach ($_FILES as $file) {            
    
                if(!empty($file['name'])) {
    
                    $uploaded_file = $file['name'];
                    $moveme = $uploaddir.$uploaded_file;
    
                    move_uploaded_file($file['tmp_name'], $moveme);
    
                }    
    
            }
    
            apc_store('files_'.$s_progressId, $_FILES);
            die();
    }
    

    That way I could iterate through the $_FILES array without knowing the name of the input. I noticed that it loops through a couple of times hence the if(!empty()) however in hindsight it's probably best practice anyway.