Reputation: 283
I would like to upload some files in my app on Heroku. I read some info to use S3 because it's better, but I really want to upload on Heroku. The uploaded files will no stay longer in my app.
In my local, the upload works but not in my Heroku app.
My controller:
$this->file = $_FILES["fileToUpload"];
$this->targetDir = __DIR__.'/';
if (move_uploaded_file($this->file["tmp_name"], $this->targetFile )) {
// code ...
} else {
// code ...
}
In my local folder, I found the upload file, but when I move my code on Heroku I see nothing on the folder.
I change the folder's permission to 777, it's not a good practice but I want to be sure it's not the problem.
Does anyone have a idea to upload files on Heroku?
Upvotes: 0
Views: 531
Reputation: 136880
I read some info to use S3 because it's better, but I really want to upload on Heroku. The uploaded files will no stay longer in my app.
It's not that S3 "is better". It's that changes made to Heroku's filesystem aren't persistent. They will be lost whenever your dyno restarts, which can happen as the result of something you do (e.g., deploying a new version or changing an environment variable) or as needed (dynos are restarted at least once per day as part of Heroku's regular maintenance process). There's no way around this.
You don't have to use Amazon S3, but you can't store files directly on Heroku's filesystem if you want them to survive indefinitely. (Temporary files may work fine, depending on your needs.)
I change the folder's permission to 777, it's not a good practice but I want to be sure it's not the problem.
This is irrelevant. You can set any permissions you want and your changes will still be lost on every dyno restart.
Upvotes: 2