Forums

Unable to delete File Uploaded .:: Temporary Solved ::.

mamool 28 Jun, 2009
Hi
at first i apologized for my English writing

i want to delete file uploaded

when i see a record , i put a line in bottom of fields
[attachment=0]delete_file.jpg[/attachment]


i write this code in administrator/components/com_chronocontact/admin.chronocontact.html.php

<?php
if ($table_field_title == "file_2" ) { $temp= $row->$table_field ; }
?>
<tr><td>Delete File</td>
<td>
<?php
if(isset($_POST['submit'])) {
$uploadpath = JPATH_SITE.DS."components".DS."com_chronocontact".DS.'uploads'.DS.$row->name.DS.$temp;
JFile::delete($uploadpath);}
?>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="submit" value="Click Here to delete File">
</form>
</td></tr>

But This Code doesn't work

Please Help me How to delete file uploaded ?
Max_admin 28 Jun, 2009
Hi mamool,

I believe its better to use a link not a button and use AJAX so you don't leave the page!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
nml375 28 Jun, 2009
Hi,
The problem with your current code, is that you are trying to create a form within a form, which will break the html DTD (and most browsers). Further, your mini-form lacks details as to which result-set to (re)load, and thus also which file to delete. The $_SERVER['PHP_SELF'] action won't contain any of the POST-submitted data, only GET-submitted.

/Fredrik
mamool 29 Jun, 2009
How to correct this Code ?!!! or another Code for solution . I want to delete file uploaded

Any suggestion ?

Please help me
mamool 29 Jun, 2009
i put my code out of the main form :
<input type="hidden" name="option" value="<?php echo $option; ?>" />
<input type="hidden" name="table" value="<?php echo $tablename; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="formid" value="<?php echo $formid; ?>" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="hidemainmenu" value="0">
</form>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="adminlist">
<tr><td>File Attached</td>
<td><a href="<?php echo "http://localhost/joomla1511/components/com_chronocontact/uploads/".$formname."/".$temp; ?>"><?php echo $temp; ?></a></td>
</tr>
<tr><td>Delete File</td>
<td>
<?php
if(isset($_POST['submit'])) {
$uploadpath = JPATH_SITE.DS."components".DS."com_chronocontact".DS.'uploads'.DS.$row->name.DS.$temp;
JFile::delete($uploadpath);
}
?>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="submit" value="Click Here to delete File">
</form>
</td></tr>
</table>

But still doesn't work !! 😟

How to run this Code :
$uploadpath = JPATH_SITE.DS."components".DS."com_chronocontact".DS.'uploads'.DS.$row->name.DS.$temp;
JFile::delete($uploadpath);
with Link And Ajax/Java scripts to run it ?
nml375 29 Jun, 2009
Hi,
Your code is still flawed in the extent that the form containing the delete-button does not hold any fields telling Joomla it should run the chronoforms component, and no fields telling chronoforms which form or database entry to deal with. If you check the generated page, you'd see cf already added this kind of information to the existing form. As such, I'd suggest you use this form rather than creating your second form on the page.

You will need to add the cid[] input, which points to the individual data record you'll be dealing with, and alter the task to take the value "viewdata" in order to redisplay the page. Personally, I'd look at the submitbutton() javascript function for this along with some additional javascript to add a "delete-field"...

That is, in the end of the HTML_ChronoContact::viewdataChronoContact() method, add a new hidden input named "deletefile" with default value "" (<input type="hidden" name="deletefile" id="deletefile" />).

Next, in your delete-code, replace the "if (isset($_POST['submit'])) {" with something like this:

if (JRequest::getString('deletefile') == "delete") {
  $uploadpath = JPATH_SITE.DS."components".DS."com_chronocontact".DS.'uploads'.DS.$row->name.DS.$temp;
  JFile::delete($uploadpath);
}

Also add a script declaration (for simplicity):
$script = "deletefile: function() {
  $('deletefile').value='delete';
  cid = new Element('input',
    {
      'type' : 'hidden',
      'name' : 'cid[]',
      'value' : '" . echo implode(JRequest::getVar('cid', array(), 'POST', 'array')) . "'
    }
  );
  $('adminForm').appendChild(cid);
  submitbutton('viewdata');
}";
(JFactory::getDocument())->addScriptDeclaration($script);


Finally, in order to create the delete-button, create it like this:
<a href="#" onclick="javascript: deletefile();">Delete file</a>


I have not tested this code myself, but is simply writing from memory. I believe it should work, but I'd suggest you try it on a demo/testsite before adding this to a live site.

/Fredrik
mamool 30 Jun, 2009
Hi Fredrik
I use your Code and put it inside my Code :

		 <table cellpadding="0" cellspacing="0" border="0" width="100%" class="adminlist">
	  	<tr><td>File Attached</td>
			<td><a href="<?php echo "http://localhost/joomla1511/components/com_chronocontact/uploads/".$formname."/".$temp; ?>"><?php echo $temp; ?></a></td>
			</tr>
		<tr><td>Delete File</td>
		<td>
		<?php
		if (JRequest::getString('deletefile') == "delete") {
 		 $uploadpath = JPATH_SITE.DS."components".DS."com_chronocontact".DS.'uploads'.DS.$row->name.DS.$temp;
 		 JFile::delete($uploadpath);
		}
		
		$script = "deletefile: function() {
		  $('deletefile').value='delete';
		  cid = new Element('input',
			{
			  'type' : 'hidden',
			  'name' : 'cid[]',
			  'value' : '" . echo implode(JRequest::getVar('cid', array(), 'POST', 'array')) . "'
			}
		  );
		  $('adminForm').appendChild(cid);
		  submitbutton('viewdata');
		}";
		(JFactory::getDocument())->addScriptDeclaration($script);
		?>
		<a href="#" onclick="javascript: deletefile();">Delete file</a>
					</td></tr>
		</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="table" value="<?php echo $tablename; ?>" />
	  <input type="hidden" name="task" value="" />
	  <input type="hidden" name="formid" value="<?php echo $formid; ?>" />
	 <input type="hidden" name="deletefile" id="deletefile" />
	  <input type="hidden" name="boxchecked" value="0" />
	  <input type="hidden" name="hidemainmenu" value="0">
	  </form>


But i have error :

Parse error: parse error in E:\wamp\www\joomla1511\administrator\components\com_chronocontact\admin.chronocontact.html.php on line 2844

error line : $('adminForm').appendChild(cid);


i attcahed my admin.chronocontact.html.php , i hope it can help u
[attachment=0]admin.chronocontact.html.zip[/attachment]

can u help me how to solve this problem ? Please
Max_admin 01 Jul, 2009
Hello guys,

I think that its better to do this using ChronoConnectivity since you can have a Chronoform loaded for record editing/viewing at the admin area and you can use AJAX easily with this, but please wait for the new release of Connectivity, its almost done!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
mamool 17 Jul, 2009
ChronoConnectivity only show Database recorde and there is no connectivity with File and datbase Recorde

-------------------------------

I Solved This problem Temporary

in admin form --> tab : File Uploads ---> Change place of Save file in "Images" Folder
Full upload Path: \...\..\Joomla Root\images\"Form Name"

An Now we can Delete File with "Media Manger" and we don't need use FTP for Delete Files
This topic is locked and no more replies can be posted.