Heroku / Bucketeer上传限制(S3)

时间:2017-06-17 15:30:48

标签: php heroku file-upload amazon-s3

我正在使用Heroku和他们的S3插件 - “Bucketeer”。

我有这个工作,我可以上传图像没问题。问题是我不关心上传图片。我的应用程序处理上传MP3(没有什么险恶的 - 它是本地乐队的网络应用程序)。

我无法上传MP3。它没有错误或任何错误,只是文件不会在S3中结束 - 而图像上传的方式完全相同,不行。

要添加的编辑 - 这不是文件类型问题,因为我通过上传一个非常小的mp3文件来测试,这非常有用。

以下代码:

        <form class="form" action="../model/process-track-upload.php" method="post" enctype="multipart/form-data">
              <div class="row">
                <div class="col-xs-12 col-sm-4">
                  <div class="dashboard-widget">
                      <h3>Add a song to your collection</h3>
                      <input class="input" type="text" name="trackname" placeholder="Track Name" required/>
                      <input class="input-margin" name="userfile" type="file">
                      <input type="hidden" name="userID" value="<?php echo $userID ?>" />
                      <button class="btn btn-large btn-block " type="submit" name="btn-upload">upload</button>
                  </div>
                </div>
              </form>

后端代码:

require('../vendor/autoload.php');

$s3 = Aws\S3\S3Client::factory();
$bucket = getenv('S3_BUCKET')?: die('No "S3_BUCKET" config var in found in env!');

if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['userfile']) && $_FILES['userfile']['error'] == UPLOAD_ERR_OK && is_uploaded_file($_FILES['userfile']['tmp_name'])) {

    try {

        $upload = $s3->upload($bucket, $_FILES['userfile']['name'], fopen($_FILES['userfile']['tmp_name'], 'rb'), 'public-read');
?>
        <p>Upload <a href="<?=htmlspecialchars($upload->get('ObjectURL'))?>">successful</a> :)</p>
<?php } catch(Exception $e) { ?>
        <p>Upload error :(</p>
<?php } }

1 个答案:

答案 0 :(得分:0)

这个问题的答案在于默认的php设置。

然而,当我使用Heroku时,我无法访问php.ini文件。

所以答案是创建一个.users.ini文件,就像用户创建的php.ini覆盖一样。

在该文件中,我只设置了以下参数:

<header>
  <span>Knox Enterprises Inc.</span>
  <nav>
    <i class="material-icons">menu</i>
    <a href="index.html">Home</a>
    <a href="About.html">About</a>
    <a href="Contact.html">Contact</a>
  </nav>
</header>
<main>
  <h1>I'm trying to find out a way</h1>
  <p>I'm trying to find out a way to make my nav bar and header title a part of each other. In other words, I'd like the text for my header to be on top of my nav bar or a part of it, as well as both the nav and the header text to be fixed to the top of
    the page for scrolling. I've been playing around and have gotten no where. I'm not really sure how to control the css and html for it.
  </p>
  <p>I'm trying to find out a way to make my nav bar and header title a part of each other. In other words, I'd like the text for my header to be on top of my nav bar or a part of it, as well as both the nav and the header text to be fixed to the top of
    the page for scrolling. I've been playing around and have gotten no where. I'm not really sure how to control the css and html for it.
  </p>
  <p>I'm trying to find out a way to make my nav bar and header title a part of each other. In other words, I'd like the text for my header to be on top of my nav bar or a part of it, as well as both the nav and the header text to be fixed to the top of
    the page for scrolling. I've been playing around and have gotten no where. I'm not really sure how to control the css and html for it.
  </p>
</main>

在此之后我很高兴去!