Re: DB_DataObject_FormBuilder Questions
| From: | Ken Restivo | Date: | Wed, 01 Dec 2004 16:29:31 +0000 |
| Subject: | Re: DB_DataObject_FormBuilder Questions | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15948@lists.php.net to get a copy of this message | ||
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wed, Dec 01, 2004 at 09:00:35AM +0100, S?nke Ruempler wrote:
> - Is it possible to trigger a build of a file-upload field? Or should this
> be done manually?
Just got through doing a file-upload page. I found a tutorial that got me started. Basically, what I
ended up with was:
function preGenerateForm()
{
$this->fb_preDefElements['original_filename'] =&
HTML_QuickForm::createElement('file',
'original_filename',
'File to upload:',
'maxfilesize=8388608');
}
function insert()
{
$actual =& $_FILES['original_filename'];
$unique_filename = sprintf("%d-%s", rand(1,200),
$actual['name']);
// TODO also check for a size < 1... zero-byte file. or, js?
if (is_uploaded_file($actual['tmp_name']) &&
move_uploaded_file($actual['tmp_name'],
$this->kenPath . $unique_filename) &&
chmod($this->kenPath . $unique_filename, 0644) )
{
//OK dump all the data about the file into the db
$this->disk_filename = $unique_filename;
$this->original_filename = $actual['name'];
$this->mime_type = $actual['type'];
$this->upload_date = date("Y-m-d H:i:s");
$this->file_size = $actual['size'];
// XXX bah! perms! chown, yuck. safe mode sucks.
$this->file_date = date('Y-m-d H:i:s',
filemtime($actual['tmp_name']));
return parent::insert();
}
return false;
} // end insert
function delete()
{
$result = parent::delete();
if ($result) {
unlink($this->kenPath . $this->disk_filename);
}
return $result;
}
}
I threw in some extra crap just to rename the files uniquely, which may not be necessary for your
app. I ran into some grief-- as you can see in the comments-- because "safe mode", um,
sucks, and my ISP won't turn it off. I'll have to beat up on the permissions in order to
get it to work there, although it works great on my home system.
>
> 'datetime' => 'date',
I naively tried this too. Got the same results you did. I don't think datetime is supported,
except of course as ordinary text. I don't like those popup boxes anyway, I prefer to use the
keyboard than the mouse.
- -ken
- --
- ---------------
The world's most affordable web hosting.
http://www.nearlyfreespeech.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBrfFre8HF+6xeOIcRAo2gAJ98yHKmFW9OeSw1oGBf/c8WOtG0HgCg71vd
LxhLpl2z/ZDxBWpct3N3TtY=
=1a7v
-----END PGP SIGNATURE-----