HI I have added two addition upload buttons where zip files can be uploaded on my dashboard and made available for visitors to download,
they upload fine and are available no problem , but if I have to go back into the the backend page editor to change anything and press the submit button the files get unlinked and are no longer available in my downloads page.
this is code in the view addedit file
<div class="control-group">
<label class="control-label" for="cleo_mk3_presets">CLEO MK3 Presets</label>
<div class="controls">
<input class="input-xlarge" id="input_cleo_mk3_presets" value="<?php if(!empty($recorddata[0]->cleo_mk3_presets)){echo $recorddata[0]->cleo_mk3_presets;}?>" name="input_cleo_mk3_presets" type="hidden" >
<input class="input-xlarge" id="cleo_mk3_presets " name="cleo_mk3_presets" type="file">
<?php if(!empty($recorddata[0]->cleo_mk3_presets)){
if(file_exists(DOC_ROOT_FRONT."/software/presets/".$recorddata[0]->cleo_mk3_presets)){ ?>
<a href="<?php echo FRONT_URL; ?>/software/presets/<?php if(!empty($recorddata[0]->cleo_mk3_presets)){echo $recorddata[0]->cleo_mk3_presets;}?>" target="_blank" title="Open File"><i class="glyphicon glyphicon-file"></i></a>
<a href="javascript:void(0)" onclick="deletefiles('<?php echo rtrim(strtr(base64_encode("path=".DOC_ROOT_FRONT."/software/presets/".$recorddata[0]->cleo_mk3_presets."&id=".$recorddata[0]->prod_id."&field=cleo_mk3_presets"), '+/', '-_'), '=')?>');" title="Delete"><i class="icon-remove-sign"></i></a>
<?php }}?>
</div>
</div>
<div class="control-group">
<label class="control-label" for="oyster_presets">oyster presets</label>
<div class="controls">
<input class="input-xlarge" id="input_oyster_presets" value="<?php if(!empty($recorddata[0]->oyster_presets)){echo $recorddata[0]->oyster_presets;}?>" name="input_oyster_presets" type="hidden" >
<input class="input-xlarge" id="oyster_presets " name="oyster_presets" type="file">
<?php if(!empty($recorddata[0]->oyster_presets)){
if(file_exists(DOC_ROOT_FRONT."/software/presets/".$recorddata[0]->oyster_presets)){ ?>
<a href="<?php echo FRONT_URL; ?>/software/presets/<?php if(!empty($recorddata[0]->oyster_presets)){echo $recorddata[0]->oyster_presets;}?>" target="_blank" title="Open File"><i class="glyphicon glyphicon-file"></i></a>
<a href="javascript:void(0)" onclick="deletefiles('<?php echo rtrim(strtr(base64_encode("path=".DOC_ROOT_FRONT."/software/presets/".$recorddata[0]->oyster_presets."&id=".$recorddata[0]->prod_id."&field=oyster_presets"), '+/', '-_'), '=')?>');" title="Delete"><i class="icon-remove-sign"></i></a>
<?php }}?>
</div>
</div>
And here is the code from the controller…
if(isset($_FILES) && isset($_FILES["cleo_mk3_presets"]["name"]))
{
/* Unlink previous file */
if(!empty($_POST['prod_id']))
{
$result = $this->productsmodel->getFormdata($_POST['prod_id']);
if(!empty($result[0]->cleo_mk3_presets))
{
$cleo_mk3_presets_path = DOC_ROOT_FRONT."/software/presets/".$result[0]->cleo_mk3_presets;
if(file_exists($cleo_mk3_presets_path))
{
unlink($cleo_mk3_presets_path);
}
}
}
$thumnail_value = '';
$config['upload_path'] = DOC_ROOT_FRONT."/software/presets/";
$config['max_size'] = '1000000';
$config['allowed_types'] = '*';
//$config['file_name'] = md5(uniqid("100_ID", true));
$config['file_name'] = $_FILES["cleo_mk3_presets"]["name"];
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload("cleo_mk3_presets"))
{
$image_error = array('error' => $this->upload->display_errors());
echo json_encode(array("success"=>"0","msg"=>$image_error['error']));
exit;
}
else
{
$image_data = array('upload_data' => $this->upload->data());
$thumnail_value = $image_data['upload_data']['file_name'];
}
}
else
{
$thumnail_value = $_POST['cleo_mk3_presets'];
}
$data['cleo_mk3_presets'] = $thumnail_value;
if(isset($_FILES) && isset($_FILES["oyster_presets"]["name"]))
{
/* Unlink previous file */
if(!empty($_POST['prod_id']))
{
$result = $this->productsmodel->getFormdata($_POST['prod_id']);
if(!empty($result[0]->oyster_presets))
{
$oyster_presets_path = DOC_ROOT_FRONT."/software/presets/".$result[0]->oyster_presets;
if(file_exists($oyster_presets_path))
{
unlink($oyster_presets_path);
}
}
}
$thumnail_value = '';
$config['upload_path'] = DOC_ROOT_FRONT."/software/presets/";
$config['max_size'] = '1000000';
$config['allowed_types'] = '*';
//$config['file_name'] = md5(uniqid("100_ID", true));
$config['file_name'] = $_FILES["oyster_presets"]["name"];
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload("oyster_presets"))
{
$image_error = array('error' => $this->upload->display_errors());
echo json_encode(array("success"=>"0","msg"=>$image_error['error']));
exit;
}
else
{
$image_data = array('upload_data' => $this->upload->data());
$thumnail_value = $image_data['upload_data']['file_name'];
}
}
else
{
$thumnail_value = $_POST['oyster_presets'];
}
$data['oyster_presets'] = $thumnail_value;
/* cleo_mk3_presets */
if(!empty($result[0]->cleo_mk3_presets))
{
$cleo_mk3_presets_path = DOC_ROOT_FRONT."/software/presets/".$result[0]->cleo_mk3_presets;
if(file_exists($cleo_mk3_presets_path))
{
unlink($cleo_mk3_presets_path);
}
}
/* oyster_presets */
if(!empty($result[0]->oyster_presets))
{
$oyster_presets_path = DOC_ROOT_FRONT."/software/presets/".$result[0]->oyster_presets;
if(file_exists($oyster_presets_path))
{
unlink($oyster_presets_path);
}
}
How do I stop the files being unlinked when I press the submit button. ?