在Drupal上使用POST提交webform中的文件(AS3)

时间:2014-10-23 05:00:41

标签: actionscript-3 drupal-7 drupal-webform

我有这个图像,我用它将它转换为BitmapData。我在localhost drupal网站上有一个webform。在webform中,我有一个文件字段和一些其他文本字段。现在问题是我用一个简单的URLVariable来提交我的所有文本字段:

var requestVars:URLVariables = new URLVariables();
requestVars['submission[data][1][values][0]']= values.text;

但我不知道提交文件的语法。请帮助!

1 个答案:

答案 0 :(得分:0)

要使用AS3上传文件,您可以使用FileReference.upload

在这里查看示例:FileReference example (Adobe)

修改:

在adobe的最后一个例子中我们有这个:

var file:FileReference = FileReference(event.target); file.upload(uploadURL);

因此,我们的Flash会将文件发送到uploadURL,在我们的示例中,这是一个 ColdFusion 脚本( .cfm )。

要使用 php 执行此操作,请查看此处:http://php.net/manual/en/features.file-upload.post-method.php

在服务器端使用 php 的示例:

AS3代码

...
var uploadURL = 'http://your-site/your-php-script.php';
...
var file:FileReference = FileReference(event.target);
file.upload(uploadURL);

PHP代码(your-php-script.php)

<?php

    // set uploads dir
    $uploads_dir = '/uploads_dir';

    if (!empty($_FILES)) {

        $temp_file = $_FILES['Filedata']['tmp_name'];
        $target_path = $_SERVER['DOCUMENT_ROOT'] . $uploads_dir;
        $target_file = rtrim($target_path,'/') . '/' . $_FILES['Filedata']['name'];

        // move uploaded file from temp dir to target dir
        move_uploaded_file($temp_file, $target_file);
    }

?>