uploadify没有在switch / if - else语句中上传

时间:2012-07-19 04:26:24

标签: php jquery

我一直在使用Uploadify插件上传文件。 基本上,我需要上传不同类型的文件(照片,平面图,小册子)

所以,下面是我的uploadify代码(上传表单)

<? $sid = session_id();  ?>

$(document).ready(function() {
    $('#file_upload').uploadify({
        'uploader'  : 'js/uploadify214/uploadify.swf',
        'script'    : 'uploader.php?pid=<? echo $pid; ?>&type=<? echo $type; ?>',
        'scriptData': {'session': '<? echo $sid; ?>'},
        'multi': true, // enable multiple upload
        'queueSizeLimit': 5, // number of file at once
        'onQueueFull': function(event, queueSizeLimit) {
            alert("You can only upload " + queueSizeLimit + " files at once");
            return false;
        },
        'cancelImg' : 'js/uploadify214/cancel.png',
        'auto'      : false,
        'onAllComplete' : function(event,data) {
              window.location = "files.php?pid=<? echo $pid; ?>" // redirect to previous page
        }
    });
});

所有上传内容均由 uploader.php 处理 以下是代码

session_id($_REQUEST['session']);
require_once('function.php');

$pid = $_REQUEST['pid'];
$type = $_REQUEST['type'];
$photo_file = $_FILES['Filedata'];
$photo_tags = 'test';
$status = '1';
$inuse = 0;

// the function will run if i put it here
property_photo_upload($user_id, $pid, $photo_file, $photo_tags, $inuse, 'photo');

// but if i put it in switch / if-else statement, the code will not run
switch($type){
    case 'photo' :
        property_photo_upload($user_id, $pid, $photo_file, $photo_tags, $inuse, 'photo');
        break;

    case 'floorplan' :
        property_doc_upload($user_id, $pid, $photo_file, $photo_tags, $inuse, 'floorplan');
        break;

    case 'brochure' :
        property_doc_upload($user_id, $pid, $photo_file, $photo_tags, $inuse, 'brochure');
        break;
}

所以,问题是如果我把上传功能OUTSIDE / WITHOUT切换/ if-else语句,上传进度可以运行没有任何问题。 但是当我把这个函数放在switch / if-else语句中时,突然上传不起作用。

我需要switch语句,以便我的代码可以处理不同文件类型的上传。

非常感谢任何帮助。 抱歉,我的英语不好,问题很长。 提前致谢

1 个答案:

答案 0 :(得分:0)

主要原因是$ type的变量。

什么类型的$ type?

调用var_dump

的功能