PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old January 6th, 2003, 03:04 PM
wap wap is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 20 wap User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Deleting an image file with php

I can upload jpg images to my server no problem. The images take on the names of the id field in the MySql database followed by front and back

eg

3456front.jpg
3456back.jpg

As the database is going to be quite large, i have found this to be the best way rather than adding blob fields to the db. I then just echo [id]front.jpg and [id]back.jpg as the image urls.

Problem is, i have an admin page that allows for deleting records from the db but i am unsure how to delete the images from the server with the corresponding [id] number.

Hope someone can help me out with this. Thanks.

Reply With Quote
  #2  
Old January 6th, 2003, 06:09 PM
Attila Attila is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 67 Attila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Here is a very simple script file I use.

PHP Code:
 $file $flocation
if (
file_exists($file)) 
    { 
        
unlink("$file"); 
    } 


Hope this helps....I also delete the information in the database after the file is unlinked.
__________________
Thanks,
Attila
http://www.glorynaspiration.com
http://www.abitofthings.com

Reply With Quote
  #3  
Old January 7th, 2003, 10:16 AM
hadley hadley is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 63 hadley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
You'll need to be very careful with a script that deletes files. If you're not, it will be easy for someone to delete arbitrary files from your site. That is the big disadvantage of not using a database to store your files.

Hadley

Reply With Quote
  #4  
Old January 7th, 2003, 11:18 AM
wap wap is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 20 wap User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for you help and advice. It's dificult for me at this stage to decide on weather to hold the images in a blob field of the database or just a link reference as most of the articles i've read have conflicting advice.

I plan to have all my admin scripts in a folder with an .htacess file to password protect the whole folder. Is this the most secure password method of protecting all my admin scripts.

Basically I want all my admin scripts to be as secure as possible and I imagine the datadase to become quite large and i'm led to believe that having many thousand image files in the database will slow the site down conciderably hence the reason for having a link ref field instead. I don't want to just leave files on the server where the database entry has been deleted as this will just waste valuable space on my chosen hosts server.

Reply With Quote
  #5  
Old January 7th, 2003, 11:30 AM
hadley hadley is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 63 hadley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I would question your assumption that having many image files in the database is going to slow your server down. All a database is, really, is a way of indexing files on disk so that you can find the ones you want rapidly.

I have a site with well over 50meg of files stored in a mySQL database and have not had any performace problems.

Hadley

Reply With Quote
  #6  
Old January 7th, 2003, 11:58 AM
wap wap is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 20 wap User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks again Hadley for your reply. This is what I mean by conflicting advice between different articles i've read. Some say storing large image files in a db will slow the site down and some say it makes virtually no difference.

I can't make any assumptions myself apart from things i read written by the pros as i'm quite new to all this, but it is hard with so much conflicting info out there. I think my only solution really is to try things out for myself.

Once again thanks for your help.

Reply With Quote
  #7  
Old January 12th, 2003, 03:59 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Quote:
Originally posted by wap
Thanks again Hadley for your reply. This is what I mean by conflicting advice between different articles i've read. Some say storing large image files in a db will slow the site down and some say it makes virtually no difference.

I can't make any assumptions myself apart from things i read written by the pros as i'm quite new to all this, but it is hard with so much conflicting info out there. I think my only solution really is to try things out for myself.

Once again thanks for your help.
The only way a blob will slow you down is if you have bad database design. If you have a table with BLOBs, make sure you have a simple "id" field which is basically an auto_increment integer and have it as the primary key. vbulletin.com has a freakin huge database with hundreds of megs of blobs, and they don't have a problem. That's all the evidence you need. Good database design means no problems with speed.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Deleting an image file with php


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway