Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Uploadify中传递和接收formData值?_Php_Javascript_Jquery_Upload_Uploadify - Fatal编程技术网

Php 如何在Uploadify中传递和接收formData值?

Php 如何在Uploadify中传递和接收formData值?,php,javascript,jquery,upload,uploadify,Php,Javascript,Jquery,Upload,Uploadify,我一直在尝试使用formData设置将uploadify客户端的数据传递和修改到服务器文件uploadify.php。我已经尝试了许多在这里和上传论坛上发布的解决方案,但没有任何效果 最初,两个formData值都设置为字符串“empty”,然后在开始上载时,eAlias设置为2,eDate设置为日期。然后,服务器脚本通过POST接收这些值,并将其回显到客户端脚本,客户端脚本在警报中显示这些数据(在onUploadSuccess中)。在所有可能尝试的解决方案中,值都是“”或“空”,即onUplo

我一直在尝试使用formData设置将uploadify客户端的数据传递和修改到服务器文件uploadify.php。我已经尝试了许多在这里和上传论坛上发布的解决方案,但没有任何效果

最初,两个formData值都设置为字符串“empty”,然后在开始上载时,eAlias设置为2,eDate设置为日期。然后,服务器脚本通过POST接收这些值,并将其回显到客户端脚本,客户端脚本在警报中显示这些数据(在onUploadSuccess中)。在所有可能尝试的解决方案中,值都是“”或“空”,即onUploadStart中formData键上的设置不起作用

我在下面介绍了大部分客户端脚本和服务器脚本

任何帮助或建议都将不胜感激,谢谢

客户端脚本:
问题正如我所想;这是因为我使用了uploadify按钮的多个实例,并使用.uploadifyfile类引用它们。Uploadify在使用类时似乎不能完全工作

我提出的可能是最基本的解决方案是使用“onSelect”函数将按下按钮的id存储到全局变量(window.uploadid)中,然后在“onUploadStart”函数中使用它。现在,例如,当按下第二个按钮时,fileType属性将成功更改为finalDetails

我已经考虑过使用,但在本例中,它们似乎不适用于id,只适用于类

我毫不怀疑,下面的代码会有一些优化,但我希望它能拯救那些和我一样工作了很多小时的人

<script type="text/javascript">
$(document).ready(function() 
{
    $(".uploadifyfile").uploadify(
    {
        ...
        'method'        : 'post',
        'formData'      : { 'eventDate' : 'notSet', 'eventVenue' : 'notSet', 'fileType' : 'notSet' },
        'onUploadStart' : function(file) 
        {
            var eventDate = "<?php echo $this->row->dates; ?>";
            var eventVenue = "<?php echo JFilterOutput::stringURLSafe($this->row->venue); ?>";
            $(uploadid).uploadify('settings','formData',{ 'eventDate' : eventDate, 'eventVenue' : eventVenue, 'fileType' : fileType });
        },
        'onSelect' : function(event, ID, fileObj)
        {
            alert('event.id:' + event.id);

            var eid = event.id;             // To determine which button was pressed

            if(eid == "SWFUpload_0_0")      // Flyer upload
            {
                window.buttonPressed = "custom01";
                window.uploadid = "#file_upload";
                window.fileType = "flyer";
            }
            else if(eid == "SWFUpload_1_0") // Final Details upload
            {
                window.buttonPressed = "custom02";
                window.uploadid = "#file_upload2";
                window.fileType = "finalDetails";
            }
            ...
        }
    });
});
</script>

...
<input type="file" name="file_upload" id="file_upload" class="uploadifyfile" />
...
<input type="file" name="file_upload2" id="file_upload2" class="uploadifyfile" />

$(文档).ready(函数()
{
$(“.uploadifyfile”).uploadify(
{
...
'method':'post',
'formData':{'eventDate':'notSet','EventVincement':'notSet','fileType':'notSet'},
“onUploadStart”:函数(文件)
{
var eventDate=“”;
var eventvention=“”;
$(uploadid).uploadify('settings','formData',{'eventDate':eventDate,'eventVenue':eventVenue,'fileType});
},
“onSelect”:函数(事件、ID、fileObj)
{
警报('event.id:'+event.id');
var eid=event.id;//确定按下了哪个按钮
如果(eid==“SWFUpload_0_0”)//传单上传
{
window.buttonPressed=“custom01”;
window.uploadid=“#file_upload”;
window.fileType=“flyer”;
}
else if(eid==“SWFUpload_1_0”)//最终细节上传
{
window.buttonPressed=“custom02”;
window.uploadid=“#文件_upload2”;
window.fileType=“finalDetails”;
}
...
}
});
});
...
...

您的客户端代码是正确的。我使用相同的代码,它工作得很好。因此,您最好使用id生成uploadify实例,而不是类

您应该使用FireBug或Chrome的JavaScript控制台对其进行调试。您是否使用了一个简单的/演示的示例?您的代码对我来说似乎很有效,可能是另一个代码块中存在问题。请尝试一个最简单的代码来发布一些东西,你会看到这行代码是否正确var eventDate=“”;它可能输出错误的内容,并使代码无法工作,请尝试调试eventDatevariable@Alexander我已经尝试过用FireBug调试它,这让我达到了现在的阶段。@TrinhHoangNhu我认为它也能工作。我在Joomla网站上使用它,Joomla往往会把事情搞得一团糟,但我已经设法让脚本的其他部分正常工作了。是的,我确信这行是正确的,它返回页面所关注的事件的日期,但是,我会调试它,看看会发生什么。
$targetFolder = '/xx/uploads'; // Relative to the root

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
    $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];

    // Set $someVar to 'someValue'
    $eventAlias = $_POST['eAlias'];
    $eventDate = $_POST['eDate'];

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

    if (in_array($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($tempFile,$targetFile);
        echo $targetFolder . '/' . $_FILES['Filedata']['name'];
        echo ' eventAlias: '.$eventAlias.' eventDate: '.$eventDate;
    } else {
        echo 'Invalid file type.';
    }
}
<script type="text/javascript">
$(document).ready(function() 
{
    $(".uploadifyfile").uploadify(
    {
        ...
        'method'        : 'post',
        'formData'      : { 'eventDate' : 'notSet', 'eventVenue' : 'notSet', 'fileType' : 'notSet' },
        'onUploadStart' : function(file) 
        {
            var eventDate = "<?php echo $this->row->dates; ?>";
            var eventVenue = "<?php echo JFilterOutput::stringURLSafe($this->row->venue); ?>";
            $(uploadid).uploadify('settings','formData',{ 'eventDate' : eventDate, 'eventVenue' : eventVenue, 'fileType' : fileType });
        },
        'onSelect' : function(event, ID, fileObj)
        {
            alert('event.id:' + event.id);

            var eid = event.id;             // To determine which button was pressed

            if(eid == "SWFUpload_0_0")      // Flyer upload
            {
                window.buttonPressed = "custom01";
                window.uploadid = "#file_upload";
                window.fileType = "flyer";
            }
            else if(eid == "SWFUpload_1_0") // Final Details upload
            {
                window.buttonPressed = "custom02";
                window.uploadid = "#file_upload2";
                window.fileType = "finalDetails";
            }
            ...
        }
    });
});
</script>

...
<input type="file" name="file_upload" id="file_upload" class="uploadifyfile" />
...
<input type="file" name="file_upload2" id="file_upload2" class="uploadifyfile" />