Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Best Way to Store Images
Old 03-29-2005, 04:57 PM Best Way to Store Images
Average Talker

Posts: 15
Trades: 0
Hi,

I am designing a rather complex web program that I intend to sell to many people, but host on my own server. Users of this program will want to customize their pages and will want to upload different header images and user photos.

As we all know, upload forms are extremely dangerous/insecure and I really don't want to get hacked through one (especially if I have 50 vulnerable users on my server).

Since one of the biggest problems with these forms is the actual upload validation and movement (move_uploaded_file();) I want to avoid actually using physical files and I think I might opt for storing the files in a MySQL database in an Images table.

I have many concerns, but first and foremost: will this guarantee me more security? For example, if someone sneaks through my upload script a PHP file and it is stored in a MySQL database as a binary file (BLOB), it won't be able to do its dirty work... right?

Another big question is whether this will slow my site down or not. I'm storing each install in a different database but if I have, lets say, a dozen 2MB BLOB images stored per site, and there are 50 sites on my server will MySQL have a heart attack?

Anyway, I know that hundreds of people have discussed this and I've browsed several different forums and from what I can tell people don't like it. On the other hand, I'm especially paranoid about upload scripts and I don't trust my anti-hacker logic at all, so I'll do anything to prevent an attack

Thanks for your help,
kmkz

Last edited by kmkz; 03-29-2005 at 05:09 PM..
kmkz is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-30-2005, 12:05 PM
simptech's Avatar
Skilled Talker

Posts: 81
Location: Cape Coral, Florida, United States
Trades: 0
You are asking for problems if your store images in a database. The queries will slow down and processes will eventually take forever to finish.

USE PHYSICAL FILES. Databases are not meant to hold such large amounts of BINARY data unless absolutely necessary.

Why not just use something like...

PHP Code:
if ($_FILES['userfile']['error'] == 0) {
  
$result getimagesize($_FILES['userfile']['tmp_name']);
  switch (
$result[2]) {
    case 
1//gif
    
case 2//jpg
    
case 3//png
     
move_uploaded_file($_FILES['userfile']['tmp_name'], "/path/to/dir/filename.ext");
     break;
    default:
     echo 
"Only GIF, JPG and/or PNG image files may be uploaded!";
     exit;
  }
}
?> 
should cover you on allowing only image uploads
__________________

Please login or register to view this content. Registration is FREE

FREE PHP scripts for your website!
simptech is offline
Reply With Quote
View Public Profile
 
Old 03-30-2005, 12:58 PM
Average Talker

Posts: 15
Trades: 0
Hmm... I think I'll opt for that.... lets just hope I dont get hacked :P

Thanks!
kmkz is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Best Way to Store Images
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17451 seconds with 12 queries