阿里云9折优惠推荐码:WR3WCX

阿里云9折优惠推荐码:WR3WCX

首次购买阿里云包年包月云服务器ECS和云数据库RDS时,使用推荐码可享受原价9折优惠
1、推荐码使用规则?
适用订单:首次购买包年包月云服务器ECS和云数据库RDS的订单
优惠折扣:享受原价9折优惠。
有效期: 推荐码限量限时,请尽快使用。
2、如何使用?
选好产品->立即购买->确认订单环节->点击「我有推荐码」->输入推荐码->立享9折!
TB1.8loIFXXXXcOXpXXkDxZRXXX-798-356

阿里云 OSS 图片上传iframe 实现异步上传

阿里云 OSS 图片上传iframe 实现异步上传 相关代码:
index.php:

<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
if (isset($_POST) && !empty($_POST)) {
    echo "<pre>";
    var_dump($_POST);
    die;
}
?>
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://filela.b0.upaiyun.com/js/jquery-1.9.0.min.js"></script>
    </head>
    <body>
        <h1>添加操作</h1>
        <form action="" method="post" >
            <iframe src="upload.php"  frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes"></iframe><br/>
            名称: <input type="text" value="" name="name">
            <div id="res"> </div>
 
            <input type="submit" value="submit" />
        </form>
 
    </body>
</html>

upload.php

<?php
$access_id = '';
$access_key = '';
$policy = '{"expiration": "2120-01-01T12:00:00.000Z","conditions":[{"bucket": "ioutsider" },["content-length-range", 0, 104857600]]}';
$policy = base64_encode($policy);
$signature = base64_encode(hash_hmac('sha1', $policy, $access_key, true));
$file_name = date('Y') . '/' . date('m') . '/' . md5(microtime(true)) . '.jpg';
//print_r(get_headers('http://ioutsider.oss-cn-shenzhen.aliyuncs.com')); 
?>
 
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://filela.b0.upaiyun.com/js/jquery-1.9.0.min.js"></script>
    </head>
    <body>
        <form id="upload" action="http://ioutsider.oss-cn-shenzhen.aliyuncs.com" method="POST" enctype="multipart/form-data">
 
            <label for="file">选择文件:</label>
            <input type="hidden" name="OSSAccessKeyId" id="OSSAccessKeyId"  value="<?php echo $access_id; ?>" />
            <input type="hidden" name="policy" id="policy"  value='<?php echo $policy; ?>' />
            <input type="hidden" name="Signature" id="Signature"  value="<?php echo $signature; ?>" />
            <!--<input type="hidden" name="key" id="key"  value="upload/${filename}" />-->
            <input type="hidden" name="key" id="key"  value="<?php echo $file_name; ?>" />
            <input type="hidden" name="success_action_redirect" value="http://iphotos.me/res.php?img=<?php echo $file_name; ?>" />
            <input type="file" name="file" id="file" />
            <input type="submit" name="upload" value="上传" />
        </form>
    </body>
</html>

上传成功后跳转的页面:

<!DOCTYPE html>
<html>
    <head>  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://filela.b0.upaiyun.com/js/jquery-1.9.0.min.js"></script>
    </head>
    <body>
        <?php $img = $_GET['img']; ?>
        <?php if ($img): ?>
            <img src='http://ioutsider.oss-cn-shenzhen.aliyuncs.com/<?php echo $img; ?>' width='200' height='200' />
            <script>
                $(function(){
                    alert('上传成功');
                    window.parent.$('#res').append("<input type='hidden' value='<?php echo $img ?>' name='path'>")
                })
            </script>
        <?php endif; ?>
    </body>
</html>

阿里云OSS 通过表单直接上传文件 Post Policy

<?php
$access_id = 'ACCESS_ID';
$access_key = 'OSS_ACCESS_KEY';
$url='http://ioutsider.oss-cn-shenzhen.aliyuncs.com';//更改成你自己的地址
$policy = '{"expiration": "2120-01-01T12:00:00.000Z","conditions":[{"bucket": "ioutsider" },["content-length-range", 0, 104857600]]}';
$policy = base64_encode($policy);
$signature = base64_encode(hash_hmac('sha1', $policy, $access_key, true));//生成认证签名
?>
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <div>文件上传</div>
        <form action="<?php echo $url;?>" method="post" enctype="multipart/form-data">
            <label for="file">选择文件:</label>
            <input type="hidden" name="OSSAccessKeyId" id="OSSAccessKeyId"  value="<?php echo $access_id; ?>" />
            <input type="hidden" name="policy" id="policy"  value='<?php echo $policy; ?>' />
            <input type="hidden" name="signature" id="signature"  value="<?php echo $signature; ?>" />
            <input type="hidden" name="key" id="key"  value="${filename}" />
            <input type="file" name="file" id="file" />
            <br />
            <input type="submit" name="submit" value="确定" />
        </form>
    </body>
</html>