Connecting Tech Pros Worldwide Help | Site Map

Upload a file into DB

  #1  
Old June 29th, 2006, 10:55 AM
yonthebeach@googlemail.com
Guest
 
Posts: n/a
Hi,

how can i upload a file with PHP into my database, and allow a download
of the file on the frontend (sent to client). Do i upload then into a
BLOB field? And how to check for a max filesize (max. 1MB) and if its
bigger cancel operation.

thanks for your help
yavuz bogazci

  #2  
Old June 29th, 2006, 11:25 AM
realmehmet
Guest
 
Posts: n/a

re: Upload a file into DB



yonthebeach@googlemail.com wrote:[color=blue]
> how can i upload a file with PHP into my database, and allow a download
> of the file on the frontend (sent to client). Do i upload then into a
> BLOB field? And how to check for a max filesize (max. 1MB) and if its
> bigger cancel operation.[/color]
Why don't you upload the file to some folder and then insert link of it
to DB?

Mehmet Zahit Ates

  #3  
Old June 29th, 2006, 12:05 PM
yonthebeach@googlemail.com
Guest
 
Posts: n/a

re: Upload a file into DB



realmehmet wrote:[color=blue]
> yonthebeach@googlemail.com wrote:[color=green]
> > how can i upload a file with PHP into my database, and allow a download
> > of the file on the frontend (sent to client). Do i upload then into a
> > BLOB field? And how to check for a max filesize (max. 1MB) and if its
> > bigger cancel operation.[/color]
> Why don't you upload the file to some folder and then insert link of it
> to DB?
>
> Mehmet Zahit Ates[/color]

to be os independent and easier backup of the running app.

greets
yavuz bogazci

  #4  
Old June 29th, 2006, 08:45 PM
Richard Levasseur
Guest
 
Posts: n/a

re: Upload a file into DB


PHP already provides the OS independence.

It is better practice to store a link in the DB and the file in the
file system.

Accessing the file is also faster, as it doesn't have to go through the
database.

Backing up shouldn't be an issue. Backups should be done by scripts,
at the most you should only have to click a button or run a command to
perform a back up.

yonthebeach@googlemail.com wrote:[color=blue]
> realmehmet wrote:[color=green]
> > yonthebeach@googlemail.com wrote:[color=darkred]
> > > how can i upload a file with PHP into my database, and allow a download
> > > of the file on the frontend (sent to client). Do i upload then into a
> > > BLOB field? And how to check for a max filesize (max. 1MB) and if its
> > > bigger cancel operation.[/color]
> > Why don't you upload the file to some folder and then insert link of it
> > to DB?
> >
> > Mehmet Zahit Ates[/color]
>
> to be os independent and easier backup of the running app.
>
> greets
> yavuz bogazci[/color]

  #5  
Old June 29th, 2006, 10:05 PM
Andy Hassall
Guest
 
Posts: n/a

re: Upload a file into DB


On 29 Jun 2006 02:54:36 -0700, "yonthebeach@googlemail.com"
<yonthebeach@googlemail.com> wrote:
[color=blue]
>how can i upload a file with PHP into my database, and allow a download
>of the file on the frontend (sent to client). Do i upload then into a
>BLOB field?[/color]

Yes, BLOB is the usual name for the appropriate data type. But it depends on
what database you're using.

For downloads you either stream it out as the results of a query, or you write
it to a file and let the webserver serve that file, using the filesystem as a
cache, but keeping the database as the master, so you only need to backup the
database and not the filesystem copy.
[color=blue]
>And how to check for a max filesize (max. 1MB) and if its
>bigger cancel operation.[/color]

http://uk.php.net/manual/en/features.file-upload.php

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
  #6  
Old June 29th, 2006, 10:05 PM
Andy Hassall
Guest
 
Posts: n/a

re: Upload a file into DB


On 29 Jun 2006 12:45:34 -0700, "Richard Levasseur" <richardlev@gmail.com>
wrote:
[color=blue][color=green]
>> to be os independent and easier backup of the running app.[/color]
>
>It is better practice to store a link in the DB and the file in the
>file system.
>
>Accessing the file is also faster, as it doesn't have to go through the
>database.
>
>Backing up shouldn't be an issue. Backups should be done by scripts,
>at the most you should only have to click a button or run a command to
>perform a back up.[/color]

When you just store filenames, there's no transactional link between the
metadata in the database, and separate files on the filesystem, so it makes
writing the backup system behind the button more complicated to implement
correctly, particularly during hot backups.

Sometimes storing the files in the database along with its metadata, making it
easier to make self-consistent backups amongst other factors, offsets the
overheads. As with most things, it depends on what you're actually doing.

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing csv file into mysql db via SP bjboy2006 answers 0 November 7th, 2007 02:10 PM
uploading file into SQL 2005 using .asp jo uy answers 3 July 19th, 2006 12:25 PM
upload file to Oracle DB Mike answers 2 November 19th, 2005 04:18 AM
Upload file and convert image before inserting to db Daniel answers 1 November 18th, 2005 07:54 PM