Chapters
40 Chapters
|
4:39:58
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
28.
Deleting Files
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial is built on Symfony 4 but works great in Symfony 5!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"aws/aws-sdk-php": "^3.87", // 3.87.10
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.10.1
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.1
"knplabs/knp-paginator-bundle": "^2.7", // v2.8.0
"knplabs/knp-time-bundle": "^1.8", // 1.9.0
"league/flysystem-aws-s3-v3": "^1.0", // 1.0.22
"league/flysystem-cached-adapter": "^1.0", // 1.0.9
"liip/imagine-bundle": "^2.1", // 2.1.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.1.0
"oneup/flysystem-bundle": "^3.0", // 3.0.3
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.0
"sensio/framework-extra-bundle": "^5.1", // v5.2.4
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.2.3
"symfony/console": "^4.0", // v4.2.3
"symfony/flex": "^1.9", // v1.21.6
"symfony/form": "^4.0", // v4.2.3
"symfony/framework-bundle": "^4.0", // v4.2.3
"symfony/property-access": "4.2.*", // v4.2.3
"symfony/property-info": "4.2.*", // v4.2.3
"symfony/security-bundle": "^4.0", // v4.2.3
"symfony/serializer": "4.2.*", // v4.2.3
"symfony/twig-bundle": "^4.0", // v4.2.3
"symfony/validator": "^4.0", // v4.2.3
"symfony/web-server-bundle": "^4.0", // v4.2.3
"symfony/yaml": "^4.0", // v4.2.3
"twig/extensions": "^1.5" // v1.5.4
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.1.0
"easycorp/easy-log-handler": "^1.0.2", // v1.0.7
"fzaninotto/faker": "^1.7", // v1.8.0
"symfony/debug-bundle": "^3.3|^4.0", // v4.2.3
"symfony/dotenv": "^4.0", // v4.2.3
"symfony/maker-bundle": "^1.0", // v1.11.3
"symfony/monolog-bundle": "^3.0", // v3.3.1
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.2.3
"symfony/stopwatch": "4.2.*", // v4.2.3
"symfony/var-dumper": "^3.3|^4.0", // v4.2.3
"symfony/web-profiler-bundle": "4.2.*" // v4.2.3
}
}
18 Comments
It would have been nice to see that doctrine transaction :)
First of it's kind :D
Hey Ad F.!
Try this ;)
If removing from the database fails,
deleteFilewill never be called. IfdeleteFilefails, the database transaction is rolled back.Cheers!
for multiple files delete ?
https://stackoverflow.com/q...
Hey Cybernet2u,
But we add "Delete" button for every file, so if you want to delete multiple files - you just need to press a few "Delete" buttons, right? Or do you want to do it in a single request? Then I'm not sure about your UI, how users will choose what files to delete in a single request? Do you have any ideas? :)
Cheers!
long story short, when i delete a category, i wan't to delete every file from each blog post :)
Hey Cybernet2u,
Ah, I see :) So, what's is your problem? It depends on how much blog posts in your categories are, but you just need to fetch all the blog posts in the category you're about to delete and iterate over each post, and actually remove it. It might be a performance issue if you have a lot of posts.. well, in this case I'd recommend to look into direction of Messenger component to create a queue of deleted blog posts and handle them async. We've already released the course about Messenger component in full, see it here: https://symfonycasts.com/sc...
I hope this helps!
Cheers!
Hi guys!
I'm using dropzone to upload files but I have a problem with my system. The system deals with car maintenance and this maintenance go trough different phases; like 'in progress', 'waiting for validation', etc. The thing is that, in these phases, the user needs to upload distinct files. Which is possible with the code provided from this tutorial. But I want to hide/lock the past files so the user won't be able to delete but still be able to upload more files via the same dropzone.
Is there a way of doing this with the code provided from this tutorial? I'm sorry, I don't know much of javaScript.
Thanks in advance!
Hey Octavio,
Sorry for the late response! Unfortunately, we don't have bandwidth to help our users with personal projects. But I will try to give you some hints at least. It sounds like you just need to drop that delete button for the uploaded files, then use will still be able to add new images but will not be able to delete them.
I hope that helps!
Cheers!
How to check if file is exist then delete file in controller? Cuz I have folder in AWS S3, if the file does not exist, I get an error and I cannot delete the file in the database when I delete that file.
Hey!
In that case what you need to do is to make an API call to AWS S3 to check if the file indeed exists. This link may give you an idea of how to make the API call: https://stackoverflow.com/a...
Cheers!
i found a problem with storing the filepath
getting the path for a file like
<br />return Uploader::BLOG_IMAGE.'/'.$this->getImageFilename();<br />creates the following problem
if i want to delete an article and I have to check if the article has an image
i would do it like this
it will always try to delete <b>Uploader::BLOG_IMAGE</b>
Hey Ad F.
I don't fully understand your problem. In your example you are passing the file path of a Blog image and that's exactly what you want to do, isn't it?
the only way would be to store fullPath, right ?
yes, thats what i want, but i'm unable to check if $files is null because even if there is no image uploaded ( imageFilename is null ), it will return Uploader::BLOG_IMAGE
does it make sense now ?
Ahh I get it but if you get the ArticleReferences from an Article object, all of its references files should exist, unless it's a new reference but you can check if such object has an ID already set. Well, besided that, what you can do is a file existence check using the Filesystem, or you can add a little bit more of code to
ArticleReference::getFilepath()method so you can check if it has something set on its$filenameproperty, if it's not, then return null.I hope it makes any sense to you :p
Cheers!
anyway, i will add some code to check only if getImageFilename is null or not
all i was trying to say, is that this tutorial always presumes that the author of an Article will always upload an Image
Ohh, yea, sometimes is better to skip some edge cases when you are trying to teach something but that's why we have comments :)
Cheers!
if an Article doesn't have any uploaded files ( or imageFilename is null ) getImagePath ( actual name from tutorial still returns something - UploaderHelper::ARTICLE_IMAGE )
"Houston: no signs of life"
Start the conversation!