Connecting Tech Pros Worldwide Forums | Help | Site Map

Upload a file into DB

yonthebeach@googlemail.com
Guest
 
Posts: n/a
#1: Jun 29 '06
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


realmehmet
Guest
 
Posts: n/a
#2: Jun 29 '06

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

yonthebeach@googlemail.com
Guest
 
Posts: n/a
#3: Jun 29 '06

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

Richard Levasseur
Guest
 
Posts: n/a
#4: Jun 29 '06

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]

Andy Hassall
Guest
 
Posts: n/a
#5: Jun 29 '06

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
Andy Hassall
Guest
 
Posts: n/a
#6: Jun 29 '06

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