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.