0

I'm using lighttpd + PHP 5.4 running with FastCGI on buildroot embedded linux. I have written some time ago a modified version of PHP file upload progress script using following tutorial: http://phpmaster.com/tracking-upload-progress-with-php-and-javascript/ I was previously working on Slackware Apache with mod_php and everything worked fine.

Unfortunately, the script is not working. I have made sure that in php.ini session.upload_progress = On and sessions are enabled. I have verified that sessions are working in general by using two simple php files as in 4. post here http://quirm.net/forum/topic.php?id=3950.

The script is supposed to show loading screen and percentage of file upload. It is achieved by sending progress.php requests every 0.2 second. Unfortunately, no matter how large is the file (I use ~13 MB files for testing, I have ensured that the file upload size in php.ini accepts this size) the upload ends after first request because it returns 100. I have debbuged progress.php and it looks that the whole $_SESSION variable is empty.

Here is my form HTML code:

<form enctype="multipart/form-data" action="actions/upload_upgrade.php" method="post" target="hidden_iframe" onsubmit="upload_type='config'; startUpload('config_form')" id="config_form">
                <p class="stdtext">
                Select File:
                <input type="hidden" name="type" value="config">
                <input type="hidden" value="config_form"
                name="<?php echo ini_get("session.upload_progress.name"); ?>">
                <input type="file" size="35" name="userfile" />
                <br><br>
                <input type="submit" class="defaultbtn" name="Upload" value="Upload" onclick="showLoadingScreen(true)"/>
                </p>
            </form>

My Javascript code (please note that upload and response handling functions are made universal because they accept uploads from several different forms that are used to upload configuration, firmware etc.).

function sendUploadRequest(form_name)
{
    job_name="Upload";
    var http = createRequestObject();
    http.open("GET", "actions/progress.php?form_name="+form_name);
    http.onreadystatechange = function () { handleResponse(http,"sendUploadRequest('"+form_name+"')"); };
    http.send(null);
}

function startUpload(form_name)
{
    showLoadingScreen(true);
    postDataSync("actions/uw.php");
    document.getElementById("loadingtext").innerHTML="Uploading file...";
    setTimeout("sendUploadRequest('"+form_name+"')", 200);
}

function handleResponse(http,fun_name)
{
    hideInfo();
    var response;
    if (http.readyState == 4) 
    {
        response = http.responseText;
        document.getElementById("loadingtext").innerHTML = response + "%";

        if (response < 100)
        {
            setTimeout(fun_name, 200);
        }
        else
        {
            showLoadingScreen(false);
            if(job_name=="")
                printInfo("Job completed successfuly");
            else
            {
                if(job_name=="Upload"&&upload_type=="config")
                {
                    if(hidden_iframe.window.document.body.innerHTML=="SUCCESS")
                    {
                        printInfo(job_name+" completed successfuly");
                        showLoadingScreen(true);
                        document.getElementById("loadingtext").innerHTML="Restoring backup...";
                        var result=postDataSync("actions/extract_backup.php");
                        showLoadingScreen(false);
                        if(result.substring(0,5)=="ERROR")
                        {
                            printError("Error while extracting backup configuration:<br><br>"+result.substring(6));
                        }
                        else if(result.substring(0,7)=="SUCCESS")
                        {
                            printInfo("Backup configuration restored successfully");
                        }
                        else
                        {
                            printError("Unknown error while extracting backup. Please contact service.");
                        }
                    }
                    else
                    {
                        printInfo(job_name+" was not completed because of errors");
                    }
                }
                else
                {
                    if(hidden_iframe.window.document.body.innerHTML=="SUCCESS")
                        printInfo(job_name+" completed successfuly");
                    else
                        printError(job_name+" was not completed because of errors");
                }
            }
        }
    }
}

function createRequestObject()
{
    var http;
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
        http = new XMLHttpRequest();
    }
    return http;
}

And my PHP code progress.php:

<?php
session_start();
//print_r($_SESSION);
$key = ini_get("session.upload_progress.prefix") . $_GET['form_name'];
if (!empty($_SESSION[$key])) {
    $current = $_SESSION[$key]["bytes_processed"];
    $total = $_SESSION[$key]["content_length"];
    echo $current < $total ? ceil($current / $total * 100) : 100;
}
else {
    echo 100;
}
3
  • I don't see any call of session_start() Commented May 9, 2013 at 9:16
  • start the session_start() Commented May 9, 2013 at 9:16
  • Thanks for your response. I have edited my post to include session_start() in progress.php. I have removed it at some point while debugging. Unfortunately, that's not an issue. I used print_r for printing out whole session contents and checked the response in firebug-the $_SESSION is an empty array. Commented May 9, 2013 at 9:20

1 Answer 1

1

On http://de3.php.net/manual/de/session.upload-progress.php it's said: "Note, this feature doesn't work, when your webserver is runnig PHP via FastCGI."

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.