Reference:
(http://cakebaker.wordpress.com/2006/04/15/file-upload-with-cakephp/).
I'm trying to adopt the "file upload to database" script referenced
above to handle multiple files at once. Is possible? I'm having
difficulty with it. Here is a sample of my code:
In add.thtml:
<!-- input fields for other product information is up here -->
<div>
<label>Main Image</label> <?=$html->file('file[main]') ?>
</div>
<div>
<label>Thumb Image</label> <?=$html->file('file[thumb]') ?>
</div>
<div>
<label>Mini Image</label> <?=$html->file('file[mini]') ?>
</div>
<div>
<?php echo $html->submit('Save') ?>
</div>
The submit is first handled by the products_controller which inserts
the other input fields into the products table and then gets the
product_id. It then goes to the files_controller.
in products_controller:
if ($this->Product->save($this->data))
{
$product_id = $this->Product->getInsertId();
if($this->requestAction("/admin/files/add/$product_id"))
{
$this->flash("Your product has been added. id:
$product_id ",
'/admin/products');
}
else
{
$this->flash("Unable to upload a your image file for
product id:
$product_id", '/admin/products');
}
}
else
{
$this->flash("Unable to save your new product.",
'/admin/products');
}
in files_controller:
function admin_add($product_id)
{
if ($product_id != null)
{
if (!empty($_FILES['file']))
{
$mainFileData =
addslashes(fread(fopen($_FILES['file']['tmp_name']['main'], "r"),
$_FILES['file']['size']['main']));
$_FILES['file']['data']['main'] = $mainFileData;
$_FILES['file']['product_id']['main'] = $product_id;
// I think this is the line that's wrong
//$this->File->save($_FILES['file']);
// I also need to upload the "thumb" image and the "mini" image
}
}
}
Any suggestions?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---