how to save and update image upload programatically - concrete5
Permalink
How to save and update image upload programatically when submit button click?
My code is the following.
<?php defined('C5_EXECUTE') or die("Access Denied.");
if(isset($_POST['btnExecute'])){
$product = Express::buildEntry('product')
->setProduct_id($_POST['txtID'])
->setProduct_name($_POST['txtName'])
->setProduct_guide($_POST['txtGuide'])
->setProduct_img(????????)
->save();
}
?>
<form enctype="multipart/form-data" class="form-stacked" method="post" action="">
<table style="width: 100%;">
<tr>
<td>Product ID</td>
<td><input type="text" name="txtID" value=""></td>
</tr>
<tr>
<td>Product Name</td>
<td><input type="text" name="txtName" value=""></td>
</tr>
<tr>
<td>Product Content</td>
<td><input type="text" name="txtGuide" value=""></td>
</tr>
<tr>
<td>Product Image</td>
<td>
<?php
$al = Loader::helper('concrete/asset_library');
echo $al->file('ccm-b-file', 'fID', t('Choose File'), $bf);
$bf = File::getByID($fID);
?>
</td>
</tr>
<tr class="form-actions">
<td colspan="2">
<input type="submit" name="btnExecute" value="Execute">
</td>
</tr>
</table>
</form>
My code is the following.
<?php defined('C5_EXECUTE') or die("Access Denied.");
if(isset($_POST['btnExecute'])){
$product = Express::buildEntry('product')
->setProduct_id($_POST['txtID'])
->setProduct_name($_POST['txtName'])
->setProduct_guide($_POST['txtGuide'])
->setProduct_img(????????)
->save();
}
?>
<form enctype="multipart/form-data" class="form-stacked" method="post" action="">
<table style="width: 100%;">
<tr>
<td>Product ID</td>
<td><input type="text" name="txtID" value=""></td>
</tr>
<tr>
<td>Product Name</td>
<td><input type="text" name="txtName" value=""></td>
</tr>
<tr>
<td>Product Content</td>
<td><input type="text" name="txtGuide" value=""></td>
</tr>
<tr>
<td>Product Image</td>
<td>
<?php
$al = Loader::helper('concrete/asset_library');
echo $al->file('ccm-b-file', 'fID', t('Choose File'), $bf);
$bf = File::getByID($fID);
?>
</td>
</tr>
<tr class="form-actions">
<td colspan="2">
<input type="submit" name="btnExecute" value="Execute">
</td>
</tr>
</table>
</form>