|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller{
public function __Construct(){
parent::__construct();
define("ID",$this->session->userdata('id'));
define("USERNAME",$this->session->userdata('username'));
if(!ID || !USERNAME){
redirect("admin/login/index");
}
}
}
?>
后台登陆做了这么一个权限判断,在使用uploadify时,加这个权限判断上传就失败了,没加这个session判断,可以正常上传!
视图代码:
<?php session_save_path(FCPATH."/temp");session_start();?>
$(function() {
$('#upload').uploadify({
'swf' : "<?php echo base_url(); ?>uploadify/uploadify.swf",
'uploader' : "<?php echo site_url('admin/pai/slider_add') ?>",//服务器端脚本
'buttonText':"请选择图片",
'formData' : {'id' : "<?php echo $this->session->userdata('id')?>"},
'fileTypeDesc' : 'Image Files',
'fileTypeExts' : '*.gif; *.jpg; *.png',
'onUploadSuccess' : function(file, data, response) {
alert(data);
// alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
}
// Put your options here
});
});
控制器代码:
public function slider_add()
{
session_save_path(FCPATH."/temp");
$id = $_POST['id'];
$this->session->set_userdata('id',"$id");
session_start();
p(ID);
// if($_FILES['Filedata']['error']==0){
// //检测是否为合法上传文件
// if(is_uploaded_file($_FILES['Filedata']['tmp_name'])){
// is_dir("uploads/slider") || mkdir("uploads/slider","0777",true);//创建上传目录
// $toFile = 'uploads/slider/'.time().mt_rand(1,1000).strrchr($_FILES['Filedata']['name'],'.');//目标文件名
// if(move_uploaded_file($_FILES['Filedata']['tmp_name'],$toFile)){
// echo json_encode(array('error'=>0,"url"=>$toFile));exit;
// }
// }
// }
// //上传失败
// echo json_encode(array('error'=>1));exit;
}
请大神提供下思路,弄了一个下午了,还是没搞过来!
|
|