0

I have Apache 2.4 installed on Windows and PHP running on the same server "Windows Server 2008 R2" without using IIS.

I have a PHP script that should upload files on to the server.

Here is my PHP code

if (!empty($_FILES) && $actualToken == $verifyToken) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath =  ROOT_FIXED . UPLOAD_DIR . $targetFolder;   //$_SERVER['DOCUMENT_ROOT']
    $targetPath = str_replace( "//", "/", $targetPath);
    $new_filename = USER_ID . '_' . time() . '_' . str_replace(" ", "_", $_FILES['Filedata']['name']);
    $targetFile = $targetPath . $new_filename;

    $fileParts = pathinfo($new_filename); 

    if (in_array(strtolower($fileParts['extension']),$fileTypes)) {
        move_uploaded_file($tempFile,$targetFile);      
        $msg_res = trim($new_filename);
    } else {

        $msg_res = 'INVALID';
    }
}

When I upload the file I do see a .tmp file created in the designated temporary folder location. But after the file is uploaded it is removed from the temporary folder but it is not being moved to the permanent location for some reason.

I am not sure if it is a permission issue or not but I am attaching screenshots of the permissions on the folders.

I have also modified the php.ini file and added

upload_tmp_dir = 'C:\php\temp_files'

so the temp files should be going into the above location "and they are."

This screenshot show the Apache is Logging on as "Local system account" enter image description here

This screenshot show the security settings on the folder where the file should be permanently moved to enter image description here

Jaylen
  • 39,043
  • 40
  • 128
  • 221
  • Did you debug your script? Did you make sure that $targetFile contains a valid path? Did you make sure the execution is hitting the function move_uploaded_file? What's the final value of $msg_res? – lbrandao Oct 15 '14 at 21:13
  • yes, I did prior posting my question. – Jaylen Oct 15 '14 at 21:14
  • Did you check what move_uploaded_file is returning? – lbrandao Oct 15 '14 at 21:15
  • `$targetFolder` that's a stray variable. Add error reporting to the top of your file(s) right after your opening ` – Funk Forty Niner Oct 15 '14 at 21:20
  • this `move_uploaded_file($tempFile,$targetFile)` returns 1. I do have the display_errors and E_ALL but I don't see anything – Jaylen Oct 15 '14 at 21:43
  • Try changing the target path to something inside Apache DocumentRoot directory. – kums Oct 15 '14 at 23:19
  • I am no longer getting the 302 error but the temp file is not being moved to the permanent path. I do not see any error but it does not make it to the final path – Jaylen Oct 21 '14 at 23:23

0 Answers0