正文 3034字数 872,903阅读

上传文件
<?php require_once 'vendor/autoload.php'; header('Access-Control-Allow-Origin:*'); use Qiniu\Auth; $bucket = ''; $accessKey = ''; $secretKey = ''; $auth = new Auth($accessKey, $secretKey); //$upToken = $auth->uploadToken($bucket); $policy = array( 'returnUrl' => 'http://test.net/fileinfo.php', 'returnBody' => '{"fname": $(key)}', ); $upToken = $auth->uploadToken($bucket, null, 3600, $policy); ?><meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.0/jquery.min.js"></script> <script type="text/ecmascript" src="md5.js"></script> <script type="text/javascript"> function check(){ var s=$('#f').val(); //alert(s); if(!s) return false; var hash = hex_md5(s); $('#key').val(hash); } </script> <form onsubmit="return check();" method="post" action="http://up.qiniu.com" enctype="multipart/form-data"> <input name="key" id="key" type="hidden" value=""> <input name="token" type="hidden" value="<?php echo $upToken;?>"> <input name="file" id="f" type="file" /> <input type="submit" value="Submit" /> </form>
Run code
Cut to clipboard

    预览图片外链文件
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" /><script> function selectInputContent(n){ obj =document.getElementById(n); obj.focus(); obj.select();} </script> <br /> <?php $ret = base64_decode($_GET['upload_ret']); $cbody = json_decode($ret, true); $dn = 'http://out.img.pan.lizhenqiu.com/'; error_log(print_r($cbody, true)); $url = $dn . $cbody['fname']; error_log($url); $stat_ = file_get_contents($url . '?stat'); $stat = json_decode($stat_, true); $mtype = $stat['mimeType']; $isImage = substr($mtype, 0, 6) == 'image/' ?> <p><input value="<?php echo $url;?>" id="select_keywords" onmouseover="selectInputContent(this.id)" /></p> <?php if($isImage){?> <img src=<?php echo $url;?> height="600px" alt=""></img> <?php }?> <p><a href="/out.php">返回</a></p>
    Run code
    Cut to clipboard

      项目 https://github.com/rwifeng/qiniudocs/tree/master/demo/simpleuploader http://developer.qiniu.com/code/v7/sdk/php.html#upload-flow
      Run code
      Cut to clipboard