remove uploaded data from database and files from server

By ht1080z - December 18, 2011

Hello,

(Using cmsb 2.13 and membership 1.06)

Is any way to remove selected images from the database?

i listed my section like:

list($accomRecords, $accomMetaData) = getRecords(array(
'tableName' => 'accoms',
'where' => "owner='".mysql_escape(@$CURRENT_USER['num'])."'",
'allowSearch' => false,
'loadUploads' => true,
// 'debugSql' => true,
));
$accomRecord = @$accomRecords[0];
// showme($accomRecord);


and displayed the items like:

<?php foreach ($accomRecord['acc_photos'] as $upload): ?>
<li>
<a href="<?php echo $upload['urlPath'] ?>" rel="prettyPhoto">
<img src="<?php echo $upload['thumbUrlPath'] ?>">
</a>
<ul class="action-list">
<li>
Actions
</li>
<li>
<a href="<?php echo $upload['urlPath'] ?>" rel="prettyPhoto">view</a>
</li>
<li>
<a href="#">delete</a>
</li>
</ul>
</li>
<?php endforeach ?>


how can i trigger and delete selected images from the 'uploads' table and remove the files from the server?

i found only very few posts in the forum about this very important part and nowhere the right answer.

Please advise,
Karls

Re: [ht1080z] remove uploaded data from database and files from server

By Jason - December 19, 2011

Hi,

Here is one approach you can take.

First, you have the "delete" link re-load the current page with the record num of the upload record in the url string like this:

<?php foreach ($accomRecord['acc_photos'] as $upload): ?>
<li>
<a href="<?php echo $upload['urlPath'] ?>" rel="prettyPhoto">
<img src="<?php echo $upload['thumbUrlPath'] ?>">
</a>
<ul class="action-list">
<li>
Actions
</li>
<li>
<a href="<?php echo $upload['urlPath'] ?>" rel="prettyPhoto">view</a>
</li>
<li>
<a href="?removeUpload=<?php echo $upload['num'];?>">delete</a>
</li>
</ul>
</li>
<?php endforeach ?>


Then, near the top of your page (before any getRecords call), you can remove the upload like this:

if (@$_REQUEST['removeUpload']) {
removeUploads("num = '".mysql_escape($_REQUEST['removeUpload'])."'");
}


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [ht1080z] remove uploaded data from database and files from server

By Jason - December 20, 2011

Hi,

Yes, if you can create a MySQL UPDATE query for any given record, using that records num field as a unique identifier.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/