There's a slight glitch when trying to upload between different file extensions. This done the trick for me: foreach(glob("uploads/profile{$id}.*") as $match) { unlink($match); } ^ I placed that immediately before calling the move_uploaded_file method. Great tutorial by the way!
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.
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 = "uploads/profile".$sessionid.".*"; This would make sure that you have the desired file name, right? Do reply if you read this :D
So just to clarify for other people, my suggestion was to pass "uploads/profile1.*" instead of "uploads/profile1*" to the glob function, and it worked out! :D
a more simpler approach would be instead of status column inside the db, to actually store the full image path plus name plus extension or null if the user didn't upload any images. So when you want to display or delete the image, u simply grab the location of the image via the database.
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.
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.
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 ;)
As stated below, if u upload 2 images from 2 different users, the extension stays the same from the first image. I know that u usually dont help people with their coding, but this is an error in the actual video and not my code. Id greatly appreciate the response. Loved the tutorial btw!
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 . "." . "*";
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
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?
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;
I found a bug. If you a 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.
@@abdulrahmann1621 no i mean in general. It's just easier in my opinion. And more newer and up to date with technology. Most new projects and companies work with these technologies. PHP is used mostly for legacy projects that have been written long time ago in PHP and need mantaining. There's many libraries, packages for nodejs that are up to date and make things easier.
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.
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?
Loving the tutorials Daniel. Am just trying to upload PDF, but as it's not an image, it won't show. It does show in the uploads folder but how would I get this to work and add a link, so that the PDF opens in the browser?
Hi Daniel! I'm sorry if I've missed anything, but what does "include_once" means? Does it means that you only include the file once, and why do you do that if that is the case?
Hi there! Here is a short explanation. include() simply includes a file into your document. include_once() first checks if the file has been included previously in your code. If so it gives an error message. If not it simply includes the file into your document. This is to make sure that your website doesn't load the same files multiple times. Hope this helped :)
on the episode in which we developed a log in system, we used prepared statements because we worked with sensitive data like passwords. as a best practice, should i always use prepared statements when working with queries inside php?
With multiple profiles it shows multiple images and if the images are of a different extension, only the extension type of the logged in user is shown.
There's one logical error when the user uploads two images with different extensions the code won't change the first one but add the second one to the uploads folder. For instance, when uploading .jpg it'll works well, but then when deciding to change the image to .png, now the uploads folder will have two images profile1.jpg & profile1.png So we have to delete the file has already inserted and replace it with the new one. but how ?!
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?
Instead of doing all that complicated stuff, What if we only update the 'status' inside 'profileimg' table to 1 and leave other operation when delete profile pic is clicked?
If you have a *profile11.jpg* in your folder the code in index.php will not work. It will show the broken img for images you upload with other extensions then .jpg Just wanted to say..
mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, array given in ....I'm getting this error on line while($rowImg = mysqli_fetch_assoc($resultImg)){...}can anyone help me out..
this works fine. simple yet effective. $filepath = "uploads/profile".$sessionid.".*"; $fileinfo = glob($filepath); if(!unlink($fileinfo[0])){ echo "Error deleting the profile image."; } else { echo "File was deleted."; } the problem is what if you have different files like profile1.docx, profile1.pdf, profile1.png, profile1.jpg, are they all be deleted?
What would happen if user 1 has just deleted its profile image and hits the delete-button another time or manually browses to the deleteprofile.php page? $fileinfo[0] would then result in the profile image of user 11, which gives user 1 the opportunity to delete the image of user 11. To prevent this from happening, one could improve deleteprofile.php by checking whether status is set to 0 for the current userid in the profileimg table, before taking any other actions. Alternatively, one could add the extension's seperator (.) to the $filename variable, i.e. $filename = "uploads/profile".$sessionid.".*"; // with the extension's seperator (.) before the * to eliminate the entire '1, 11, 111, ...' issue. When choosing this solution, you also have to remove the extension's seperator (.) in the $file variable, i.e. $file = "uploads/profile".$sessionid.$fileactualext;