How to Delete a File from a folder using PHP - php

I am currently developing a IMAGE GALLERY site. Every thing is working well and GOOD except a small Problem. For example, if i am deleting a image in the site its deleting successfully from the database and no longer displaying in the gallery. But i need to remove the specific image from the folder. Is there any chance to do that. if YES please guide me to do that.

To delete a file you need to use the unlink() function.

PHP : Delete a file, or a folder and its contents

Related

How would my databse grab the files in my server?

So I was thinking and thinking and couldn't figure it out. So I was following this tutorial which I want to implement on my site https://www.w3schools.com/php/php_file_upload.asp and on the tutorial when the user uploads their image it sends it straight to a folder, which will obviously be in the server files. Now my problem here is, if I want to display their image somewhere on their profile when they upload it, how would I go about grabbing the image from the folder, or do I have to change the code on the tutorial so that it saves in my database? I really have no clue, and I am now officially lost and anxiety is slowly falling down my imaginary tears that are illustrated by my depressed brain, and yeah.
You save the images in a specific folder, then save the filename in the database. Whenever you want to retrieve this file in your front-end you just take the filename from the database and link to wherever you put the file.

How to show images in a webpage from root directory in PHP Codeigniter?

I have made a site with Codeigniter and users have options to upload their photos there. As the photos are personal, I think keeping them on web directory is not safe. As a result, I kept them on a root directory like /var/www/images directory. Now, how I can get the images in a webpage?
Wrong Choice dear learner. you images folder needs to be accessible by your code and to the browser to render that image by the image path. For example
This is the image directory of my project. I am using all these images in different pages of my website. Some are selected dynamically by my code.
Now in your case by putting images in www folder, you are making a path of http://images/ which is not recommended by any PHP guidelines. Your images folder should be in your project root not outside.
If you want to disable folders to be viewed, just add empty index.html file, but if you try to protect images from being viewed then your website wont be able to find them too image protection in codeigniter
The code will be as safe as you make it. Well what you are doing is fine, the web server will still have to access the images.
While ignoring the rest of your code or what yo are trying to achieve, you could try referencing the images fro your webroot or probably create a symlink.
Also, I would try to put the images in another place like AWS.
If security is a concern for you, you can try building a ImagesController that checks if image exists, if user has permissions to see it and after that render it.
Uploaded images should also have some reference row inside a table in your database that can have a column which specifies if it should be public (also try to sort them to folders depending on what it represents - user profile pics, product images, etc).
I know it's a little bit of work but this would be the way I would do it.
You can check online for examples of controllers that return an image.
Good luck on your project.

How to show uploaded files in uploadcare?

I'm using uploadcare.com to store my images and files. I just started using it now. I was just wondering that how can i display the uploaded files in a web page. I looked through the documentation too. But didn't get anything to start with?
Is there anyone who have used it?
As per documentation, all images are available via CDN URL (this URL is returned by widget, it's up to you to save it). To add an image to your page just add an img tag:
<img src="http://www.ucarecdn.com/5651bbb6-c599-44bd-9c63-1db5e67db6ad/" />

Could my file structure be causing the issues with my photo upload system?

I'm trying to create a photo upload system following Adam Khourys online tutorials.
http://www.developphp.com/view.php?tid=1395 - Upload multiple files video
http://www.developphp.com/view.php?tid=1304 - User profile upload
Most of the code is like for like, but with my own variable names used instead. One major difference is instead of creating 3 different file upload fields as in the multiple upload video I created my form to allow multiple selections from just one upload field.
Below is a brief overview of the files, their location and what the page does.
create_post.php located in root directory - the page that allows for image upload
image_uploader.php located in root > includes directory - the page that contains the upload form, made as a seperate file to be included into any page that may require photo uploads.
photo_system.php located in root > parsers directory - the page that handles image upload.
When I go to the create a post page, click the link to upload image(s) all works well, I can see the form, I can even select the files I would like to try and upload but when I click the upload button nothing seems to happen, when photo_system.php should load.
I've added a line of code to photo_system.php right at the top that should bring up an alert box once the page has loaded, in an attempt to debug my issues, but I never see this unless I go directly to image_uploader.php
This has lead me to believe that maybe my relative links to files were the issue so I've tried appending $_SERVER['DOCUMENT_ROOT'] to the start of the links to ensure it can alway locate them from the root directory, currently I have it set up with a hard coded $root variable and still I can't seem to get the system to work.
Is it likey that the file structure and the way the pages interact with each other is my problem? Could anyone take a look at my code for these three files and see if they can spot anything? I've been stumped by this for a week or so now so I think its time to ask for some outside help.
I have my 3 files saved in a txt format so the code can be viewed
http://www.vwrx-project.co.uk/temp_source_code/create_post.txt
http://www.vwrx-project.co.uk/temp_source_code/image_uploader.txt
http://www.vwrx-project.co.uk/temp_source_code/photo_system.txt
It turns out that in the end I was trying to nest two tables one inside the other so this was part of my issue.
The way that I had it set up I was including the photo upload system, image_uploader.php, as a table with an action requesting the photo_system.php file which worked when I went to the image_uploader.php page directly.
I also had in my main page where the images were being uploaded a form that had been set to onsubmit = false and this was canceling out the form action of the included file.
I only found this out when I decided to try and code it straight into one file else I'd still be stuck now.

Edit the mediawiki uploaded file name

In Mediawiki, we are uploading video using mediawiki api. Its uploading fine.It will be creating as a page like "File:Test.mp4". Now we want to edit the page title alone (Like "File:Test.mp4" to "File:Sample.mp4, but the video will be same). Kindly suggest any solution for editing.
To rename a MediaWiki page, you move it. This can be done with the API, if you don't want to move it manually:
/api.php?action=move&from=File:Test.mp4&to=File:Sample.mp4&token=xxxx
When you move a file page, the corresponding file will also be renamed. A redirect will be created from the old file page, so that both [[File:Test.mp4]] and [[File:Sample.mp4]] works throughout the wiki.

Categories