1

Yesterday I integrated uploadify in a Yii application and it worked good. But suddenly I found that it does not work rather showing error HTTP Error (302). I found this is happened only firefox, IE and Crome are okay.

In below of main.php file I wrote:

<?php $timestamp = time();?>
$(function() {
    $('#file_upload').uploadify({
        'method'   : 'post',
        'auto'     :false,
        'multi'    : true,
        'formData'     : {
            'timestamp' : '<?php echo $timestamp;?>',
            'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
        },
        'swf'      : '<?php echo Yii::app()->request->baseUrl; ?>/images/uploadify.swf',
        'uploader' : '<?php echo Yii::app()->createUrl('cp/project/UploadImage')?>'

    });
});

and in controller:

public function actionUploadImage(){
    $directory = Yii::getPathOfAlias('webroot').'/images/temp';
    if (!is_dir($directory)) {
        mkdir($directory, 0777, true);
    }

    $verifyToken = md5('unique_salt' . $_POST['timestamp']);

    if (!empty($_FILES) && $_POST['token'] == $verifyToken) {

        $tempFile = $_FILES['Filedata']['tmp_name'];

        $filename  = basename($_FILES['Filedata']['name']);
        $extension = pathinfo($filename, PATHINFO_EXTENSION);
        $newName       = md5(time()).'.'.$extension;

        $targetFile = $directory . '/' . $newName;

        $fileTypes = array('jpg','jpeg','gif','png'); // File extensions
        $fileParts = pathinfo($_FILES['Filedata']['name']);

        if (move_uploaded_file($tempFile,$targetFile))
        {
            $model = new ImageTemp();
            $model->user_id = Yii::app()->user->id;
            $model->image_hash = $newName;
            $model->session_id = Yii::app()->session['imageUpload'];
            $model->save();
        }

    }
}

Everything was good but suddenly, I have been facing this error.

3
  • 1
    302 is technically not an error, it's a redirect. Based on past experience, I am guessing Firefox is not passing session cookies in the Flash request, so Yii is telling it to authorize first. If that is indeed the case, you will need to implement something similar to uploadify.com/documentation/uploadify/… . Commented Mar 25, 2014 at 6:52
  • Thanks, it helps me to fix the issue. I fixed now. Commented Mar 25, 2014 at 15:19
  • You should post the solution as an answer so others with the same problem can benefit from finding this post. Commented Mar 25, 2014 at 15:22

1 Answer 1

0

I have solved the issue and left answer here how I have fixed if anybody got any help. As per reference of uploadify http://www.uploadify.com/documentation/uploadify/using-sessions-with-uploadify/ and http://www.uploadify.com/documentation/uploadify/customizing-the-server-side-upload-script/ I wrote at the beginning of the controller :

function init(){

    if(isset($_POST['SESSION_ID'])){
        $session=Yii::app()->getSession();
        $session->close();
        $session->sessionID = $_POST['SESSION_ID'];
        $session->open();
    }
}

and initialized uploadify as:

$session_id = Yii::app()->session->sessionID;
$session_name = 'SESSION_ID';
$swf = Yii::app()->request->baseUrl.'/images/uploadify.swf';
$uploadifyImg = Yii::app()->createUrl('cp/project/UploadImage');
Yii::app()->clientScript->registerScript('uploadify', "

$(function() {
    $('#file_upload').uploadify({
        'method'   : 'post',
        'auto'     :false,
        'multi'    : true,
        'formData' : {'$session_name' : '$session_id'},
        'swf'      : '$swf',
        'uploader' : '$uploadifyImg'

    });
  });
");

It would helpful who face such issue.

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.