Home > Backend Development > PHP Tutorial > 七牛云 表单上传 回调 没执行, 不知道是怎么回事

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:45:56
Original
1245 people have browsed it

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

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

在我上传了文件之后, 应该在浏览器上得到像下面的回答:
{"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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

在我上传了文件之后, 应该在浏览器上得到像下面的回答:
{"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"}是七牛对你当前页面的回应。请仔细看文档。谢谢。- -#

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template