首頁 >後端開發 >php教程 >七牛云 表单上传 回调 没执行, 不知道是怎么回事

七牛云 表单上传 回调 没执行, 不知道是怎么回事

WBOY
WBOY原創
2016-06-06 20:45:561218瀏覽

上传也得代码, 这个代码是根据七牛例子改的:

filename: transfer-file.php

<code><?php require_once("qiniu/rs.php");
    $bucket = "supermew";
    $accessKey = "lHdMHiTmH7iC3p8EWb3SoiXW1ANhPEVwCbqqD9Ke";
    $secretKey = "gwivDGDqEwLO4bRngQnfH7V1aBUC83crFAxdAiof";
    
    Qiniu_SetKeys($accessKey, $secretKey);
    $putPolicy = new Qiniu_RS_PutPolicy($bucket);
//  $putPolicy->ReturnUrl = "http://supermew.eu5.org/test1/transfer-file.php";
    $putPolicy->callbackUrl = "http://supermew.eu5.org/test1/successful.php";
    $putPolicy->callbackBody = "name=.$key";
    $upToken = $putPolicy->Token(null);
    //echo $upToken;
?>


    
        <form method="post" action="http://up.qiniu.com/" enctype="multipart/form-data">
            <?php echo "<input name=\"token\" type=\"hidden\" value=\"$upToken\">"
            ?>
            Album belonged to:
            <input type="text" name="x:album" value="albumId"><br>
            Image to upload:
            文件名:<input type="text" name="key"> <br>
            <input type="file" name="file"><br>
            <button type="submit">Upload</button>
        </form>
    

</code>

filename: successful.php

<code><?php #定义http headers 输出
header('Pragma: no-cache');
header('Cache-Control: no-store');
header('Content-type: application/json');


//$filename = isset($_POST["name"]) ? trim($_POST["name"]):"";
//$file = fopen("successfull.txt", "w+");

//echo "filename: \n". $filename ."\nend";

//fputs($file, $filename);

//fputs($file, $filename);

//fclose($file);

die(json_encode(array("code"=>200, "data"=>array("success"=>"transfered successfully"))));
?>
</code>

在我上传了文件之后, 应该在浏览器上得到像下面的回答:
{"code":200,"data":{"success":"transfered successfully"}}
然而得到的是下面的回答
{"hash":"Fmz2iy5IyuPVGvIDLdzLHPb3NSZo","key":"kdfldjfldjflddfdfdf.jpg","x:album":"albumId"}

就像是没有执行回调一样, 这是怎么回事, 希望大侠们, 给看看。。

上传表单上得文件名还不能是中文, 这个我相信, 我自己能够解决, 上面得都是我自己根据例子学习的。

回复内容:

上传也得代码, 这个代码是根据七牛例子改的:

filename: transfer-file.php

<code><?php require_once("qiniu/rs.php");
    $bucket = "supermew";
    $accessKey = "lHdMHiTmH7iC3p8EWb3SoiXW1ANhPEVwCbqqD9Ke";
    $secretKey = "gwivDGDqEwLO4bRngQnfH7V1aBUC83crFAxdAiof";
    
    Qiniu_SetKeys($accessKey, $secretKey);
    $putPolicy = new Qiniu_RS_PutPolicy($bucket);
//  $putPolicy->ReturnUrl = "http://supermew.eu5.org/test1/transfer-file.php";
    $putPolicy->callbackUrl = "http://supermew.eu5.org/test1/successful.php";
    $putPolicy->callbackBody = "name=.$key";
    $upToken = $putPolicy->Token(null);
    //echo $upToken;
?>


    
        <form method="post" action="http://up.qiniu.com/" enctype="multipart/form-data">
            <?php echo "<input name=\"token\" type=\"hidden\" value=\"$upToken\">"
            ?>
            Album belonged to:
            <input type="text" name="x:album" value="albumId"><br>
            Image to upload:
            文件名:<input type="text" name="key"> <br>
            <input type="file" name="file"><br>
            <button type="submit">Upload</button>
        </form>
    

</code>

filename: successful.php

<code><?php #定义http headers 输出
header('Pragma: no-cache');
header('Cache-Control: no-store');
header('Content-type: application/json');


//$filename = isset($_POST["name"]) ? trim($_POST["name"]):"";
//$file = fopen("successfull.txt", "w+");

//echo "filename: \n". $filename ."\nend";

//fputs($file, $filename);

//fputs($file, $filename);

//fclose($file);

die(json_encode(array("code"=>200, "data"=>array("success"=>"transfered successfully"))));
?>
</code>

在我上传了文件之后, 应该在浏览器上得到像下面的回答:
{"code":200,"data":{"success":"transfered successfully"}}
然而得到的是下面的回答
{"hash":"Fmz2iy5IyuPVGvIDLdzLHPb3NSZo","key":"kdfldjfldjflddfdfdf.jpg","x:album":"albumId"}

就像是没有执行回调一样, 这是怎么回事, 希望大侠们, 给看看。。

上传表单上得文件名还不能是中文, 这个我相信, 我自己能够解决, 上面得都是我自己根据例子学习的。

1.上传的文件名可以是中文
2.{"code":200,"data":{"success":"transfered successfully"}}是你的服务器对七牛的Callback的回应,{"hash":"Fmz2iy5IyuPVGvIDLdzLHPb3NSZo","key":"kdfldjfldjflddfdfdf.jpg","x:album":"albumId"}是七牛对你当前页面的回应。请仔细看文档。谢谢。- -#

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn