dqoqnmb163241 2010-03-26 10:52
浏览 60
已采纳

swfupload销毁会话? PHP

hy, i need a little help here:

i use SWFupload to upload images! in the upload function i make a folder call $_SESSION['folder'] and all the files i upload are in 1 array call $_SESSION['files'] after uploads finish i print_r($_SESSION) but the array is empty? why that?

this is my upload.php:

if($_FILES['image']['name']) {
    list($name,$error) = upload('image','jpeg,jpg,png');
    if($error) {$result = $error;}
    if($name) { // Upload Successful
        $result = watermark($name);
        print '<img src="uploads/'.$_SESSION['dir'].'/'.$result.'" />';

    } else { // Upload failed for some reason.
        print 'noname'.$result;
    }
}

function upload($file_id, $types="") {
    if(!$_FILES[$file_id]['name']) return array('','No file specified');
    $isimage = @getimagesize($_FILES[$file_id]['tmp_name']);
    if (!$isimage)return array('','Not jpg');

    $file_title = $_FILES[$file_id]['name'];
    //Get file extension
    $ext_arr = split("\.",basename($file_title));
    $ext = strtolower($ext_arr[count($ext_arr)-1]); //Get the last extension

    //Not really uniqe - but for all practical reasons, it is
    $uniqer = substr(md5(uniqid(rand(),1)),0,10);
    //$file_name = $uniqer . '_' . $file_title;//Get Unique Name
    //$file_name = $file_title;
    $file_name = $uniqer.".".$ext;

    $all_types = explode(",",strtolower($types));
    if($types) {
        if(in_array($ext,$all_types));
        else {
            $result = "'".$_FILES[$file_id]['name']."' is not a valid file."; //Show error if any.
            return array('',$result);
        }
    }

    if((!isset($_SESSION['dir'])) || (!file_exists('uploads/'.$_SESSION['dir']))){
        $dirname = date("YmdHis");  // 20010310143223
        $pathtodir = $_SERVER['DOCUMENT_ROOT']."/ifunk/uploads/";
        $newdir = $pathtodir.$dirname;
        if(!mkdir($newdir, 0777)){return array('','cannot create directory');}
        $_SESSION['dir'] = $dirname;
    }

    if(!isset($_SESSION['files'])){$_SESSION['files'] = array();}
    //Where the file must be uploaded to
    $folder = 'uploads/'.$_SESSION['dir'].'/';
    //if($folder) $folder .= '/';   //Add a '/' at the end of the folder
    $uploadfile = $folder.$file_name;

    $result = '';
    //Move the file from the stored location to the new location
    if (!move_uploaded_file($_FILES[$file_id]['tmp_name'], $uploadfile)) {
        $result = "Cannot upload the file '".$_FILES[$file_id]['name']."'"; //Show error if any.
        if(!file_exists($folder)) {
            $result .= " : Folder don't exist.";
        } elseif(!is_writable($folder)) {
            $result .= " : Folder not writable.";
        } elseif(!is_writable($uploadfile)) {
            $result .= " : File not writable.";
        }
        $file_name = '';

    } else {
        if(!$_FILES[$file_id]['size']) { //Check if the file is made
            @unlink($uploadfile);//Delete the Empty file
            $file_name = '';
            $result = "Empty file found - please use a valid file."; //Show the error message
        } else {
            //$_SESSION['files'] = array();
            $_SESSION['files'][] .= $file_name;
            chmod($uploadfile,0777);//Make it universally writable.
        }
    }

    return array($file_name,$result);
}
  • 写回答

2条回答 默认 最新

  • doufenzhu7012 2010-03-26 10:58
    关注

    SWFUpload doesn't pass the session ID to the script when you upload, so you have to do this yourself. Simply pass the session ID in a get or post param to the upload script, and then in your application do this before session_start:

    if(isset($_REQUEST['PHPSESSID'])) {
        session_id($_REQUEST['PHPSESSID']);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂