Re: databases
From: Ian.H (ian_at_WINDOZEdigiserv.net)
Date: 08/07/04
- Next message: AAAAAA: "NEWBIE wants to create search functions - PHP good start???"
- Previous message: steve: "Re: Re: Re: Zend"
- In reply to: Goofy: "Re: databases"
- Next in thread: provaands: "Re: databases"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 07 Aug 2004 19:02:06 GMT
On Sat, 07 Aug 2004 17:42:41 +0100, Goofy wrote:
[ snip ]
> do u know how should save the paths and file name in the database? is there
> any tutorial? because i only know how to store text in the database. how
> should i build the links and
>> references from that information? any on-line tutorial? and something
> else. which command should i use ( php) in order to retrieve these
> information?
I'd store just the filename (grab this value from
$_FILES['field_name']['name'] (where 'field_name' is the name of your form
element).
Unless you have a highly configurable site where the upload directory
maybe dynamic, you could just define the dir and concatenate to create the
full path:
[ upload.php ]
<?php
/**
* If upload.php is in your Web root, this would prevent
* files being accessed directly without going through a script
*/
define('UPLOAD_DIR', dirname(__FILE__) . '/../files/');
$filename = $_FILES['upload_file']['name'];
/**
* Do bulk of processing
* [ ... ]
*/
if (move_uploaded_file($src, UPLOAD_DIR . $filename) {
/**
* Store $filename in database
*/
}
?>
[ download.php ]
[ example link: foo.com/download.php?id=1 ]
<?php
define('UPLOAD_DIR', dirname(__FILE__) . '/../files/');
/**
* Grab filename from database
* that matches ID #1
* (Assuming $row is your assoc array from DB)
*/
$filename = $row['filename'];
/**
* Send headers etc (see php.net under 'header')
*/
header('Content-type: application/octet-stream');
/* etc etc etc */
@readfile(UPLOAD_DIR . $filename);
exit;
?>
This is a really quick outline of how I normally do things (please note
the lack of validation in this example code) but it works pretty well.
You may want to define more info like a list (array) of mime-types
according to file extension and making the above header() call relative to
the mime-type rather than sending everything application-octet-stream:
$mimeTypes = array('
'zip' => 'archive/x-zip',
'jpg' => 'image/jpeg'
);
for example.. but there's lots you can play with maybe once you have the
base of the code sorted =)
HTH.
Regards,
Ian
-- Ian.H digiServ Network London, UK http://digiserv.net/
- Next message: AAAAAA: "NEWBIE wants to create search functions - PHP good start???"
- Previous message: steve: "Re: Re: Re: Zend"
- In reply to: Goofy: "Re: databases"
- Next in thread: provaands: "Re: databases"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|