上传也得代码, 这个代码是根据七牛例子改的:
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"}
是七牛对你当前页面的回应。请仔细看文档。谢谢。- -#