53: Delete profile image using PHP - PHP tutorial

preview_player
Показать описание
How to delete profile images from users - Learn PHP backend programming. Today we will learn how to delete profile images from our users, based of the previous episode.

➤ GET ACCESS TO MY LESSON MATERIAL HERE!

First of all, thank you for all the support you have given me!

I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!

I am now using Patreon to share improved and updated lesson material, and for a small fee you can access all the material. I have worked hard, and done my best to help you understand what I teach.

I hope you will find it helpful :)

Рекомендации по теме
Комментарии
Автор

There's a slight glitch when trying to upload between different file extensions. This done the trick for me:
as $match) { unlink($match); }
^ I placed that immediately before calling the move_uploaded_file method.
Great tutorial by the way!

esma_
Автор

At 11:08 when he wanted to solve the problem of getting the file exclusively from the uploads folder..
you just can put a dot in the filename variable so it means anything after the dot or (whatever the extension is ) after profile + id + . + EXTENSION
and so that you preserve the compiler from being confused choosing the specific image, like so:
$filename = "uploads/profile" . $sessionid . "." . "*";

omranshahrour
Автор

... and of course: thanks for your great tutorials. As a newbie I'm learning a lot. Keep up the good work!

matthiasdreyer
Автор

Wasn't able to get glob to work for whatever reason but before watching this episode I had already added a column to the profileimg table to store the extension (inserted during image upload) so I was able to use sql statements to grab the extension from the table instead.
Requires a few more lines of code compared to the glob method but worked all the same. Also had to update the column to null after deleting the image.

I still need to figure out why glob wasn't returning any results though. It looks like a very handy method to know.

pingrash
Автор

Hello Daniel, so i was thinking... Instead of doing all that complicated stuff to make sure you don't get profile11 in profile1 while globbing, why not just pass profile1.* instead of profile1* to the glob function? So your glob expression would be something like

$filename =

This would make sure that you have the desired file name, right?
Do reply if you read this :D

shashwatpratap
Автор

hi, i love your videos on php and thank you for help thousands of programmers. Can you please make a video on how we can Authenticate a user from Microsoft Active Directory because its the main thing nowadays as organizations want their employees to get authenticated from AD before using their intranet websites.

naushadjadoon
Автор

Hi denial!
I found a bug. If you upload one type of image lets say jpg and then you upload another type on top of it lets say png you will have 2 files uploaded to the server. Only 1 will show of course and then when you press the delete button once it will delete only the 1st found file and it will go back to the default profile picture but you will still have 1 more file uploaded to the server. You have to press the delete button again to delete the second file. It would be cool if you make a video on how to fix that :) Thank you.

abdulrahmann
Автор

and ofcourse thanks for your awsome tutorials you are good teacher dude

yasinmonkezi
Автор

hey dear Daniel what are these extra codes and funcs??
you could just use session to update status and return default image

yasinmonkezi
Автор

The best
The best
The best
You are the best php tutor

kingsleychibuzor
Автор

Thank you so much sir.your videos are very helpful.

modemaxit
Автор

Great video as always. I was wondering, do you have any plans on making a bigger project like we did with the login system and the comment section just writting it only using Object - oriented PHP?

matejbasic
Автор

the last lecture was how to upload images and other files and next lecture is how to delete files. I have missed the in-between lecture related to profile images so is it possible to get files of those lectures or maybe of all lectures.

atulyadav
Автор

A tiny improvement could be made: if you have a image named "my.profile1.jpg" Picking the [1] element of the array after the EXPLODE is going to return "profile", not ".jgp" extension. We should return the last element of the arraw to make sure the extension is extracted. Would make your code a bit more robust ;)

Hiturion
Автор

Hi Daniel, I was thinking why would you assemble the file name in a complicated way (1st explode() then concatenate) if you receive the complete filename of the profile image from glob() as $fileinfo[0]? I'm referring to index.php line 25-28 and deleteprofile.php line 7 to 11?

matthiasdreyer
Автор

13:07 may I ask you why aren't you now not naming the variables camel case?
like:
$fileactualext instead of $fileActualExt?
And will you please tell what is the best way to name variables?

amoghdatar
Автор

you could add the ' . ' before the * so it will be forced to find only the extension and not another pic with double 1

silvanbusuttil
Автор

plzzz make episodes on creating social network site plzzz as i watch lots of tutorials but i find that yours explanation are best and easy to understand so plzzz

TheNivesh
Автор

Is there any way to delete without having the if query and echo statements that it has or hasn't been uploaded?

victoriadonaghy
Автор

hi sir
please
in your previous, you have mentioned at one of the comments that you will show us in this video how to allow multiple extension since jpg was the only extension we could upload.
I haven't seen anything like that in your patreon.
I guess you might have forgotten
please I need your help and look forward to hearing from you back;

gabrielfono
welcome to shbcf.ru