dsfdsf23423 2016-05-04 15:16
浏览 99

$ s3-> putObject似乎使我的PHP文件的其余部分像纯字符串一样

I'm new to PHP, and I'm trying to create a web page that will upload a file onto an S3 bucket.

My script looks like this:

<? php

use Aws\S3\Exception\S3Exception;

require 'start.php';

//Global files variable does it contain something?
if (isset($_FILES['file'])){

    $file = $_FILES['file']; //This relates to the file we're uploading.

    //File details
    $name = $file['name'];
    $tmp_name = $file['tmp_name'];

    $extension = explode('.', $name); //Getting the extension of the file.
    $extension = strtolower(end($extension));

    //Giving the files some temp info
    $key = md5(uniqid()); #Generating a random file extension
    $tmp_file_name = "{$key}.{$extension}";
    $tmp_file_path =  "{$tmp_file_name}";

    var_dump($tmp_file_path);

    //Move the file
    move_uploaded_file($tmp_name, $tmp_file_path);

    try {

        //Accessing config variable
        $s3->putObject([
                'Bucket' => $config['s3']['bucket'],
                'Key' => "uploads/{$name}", //Where we actually store this on amazon S3. CAN USE $TMP_NAME
                'Body' => fopen($tmp_file_path, 'rb'), //Resource, open files - rb is reading.
                'ACL' => 'public-read' //Access control level, permissions as such
            ]);

        //Remove the file
        unlink($tmp_file_path);

    } catch (S3Exception $e) {
        die( $e->getMessage(), "
");
    }
}

?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Upload</title>
    </head>
    <body>
        <form action="upload.php" method="post" enctype="multipart/form-data">
            <input type="file" name="file">
            <input type="submit" value="Upload">
        </form>
    </body>
</html>

However, my web page looks like this

Web page

The web page should only be displaying the buttons, and I can't work out why the code after $s3-> is also displaying in my web page instead of doing what it should be.

Can anyone give me a clue as to what I've done wrong? Thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度