文件上传在Heroku环境中不起作用 [英] File upload not working in Heroku environment

查看:190
本文介绍了文件上传在Heroku环境中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地开发了一个小型的网络应用程序,一切正常。部分功能允许用户上传MP3文件。本地这一切工作正常,文件被移动到正确的目录,并可以播放。在heroku中,一切似乎都起作用,除了文件不存在。

I have developed a small web app locally and all is working fine. Part of the functionality allows the user to upload MP3 files. Locally this all works fine and the files are moved to correct directory and can be played back. In heroku everything seems to work except the files aren't there.

我的代码...

标记:

<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" type="file" name="pic" />
                      <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>

PHP:

PHP:

if(isset($_POST['btn-upload']))
{
        $pic = rand(100,1000000)."-".$_FILES['pic']['name'];
        $pic_loc = $_FILES['pic']['tmp_name'];
        $folder="../tracks/uploads/";
        if(move_uploaded_file($pic_loc,$folder.$pic))
        {
            ?><script>alert('successfully uploaded');</script><?php
        }
        else
        {
            ?><script>alert('error while uploading file');</script><?php
}
}

我不太喜欢使用环境配置等等,在这里。

I'm not awesome with environment configuration etc so it may be something going on there.

我应该添加作为一个笔记,当我推到Heroku我本地添加的文件是可用的。这只是我添加的文件,使用基于Heroku的版本的应用程序,而不是保存在正确的(或任何)目录。

I should add as a note that files I added locally are available when I push to Heroku. It's only files that I add using the Heroku based version of the app that aren't getting saved in the correct (or any) directory.

谢谢

推荐答案

我放弃了这个,并切换到S3。谢谢。

I abandoned this and switched to S3. Thanks.

这篇关于文件上传在Heroku环境中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆