Forums

Replacing Existing Docs Through "Upload Files" Function

swmckay 08 Nov, 2012
Hello,

I am using the Upload Files function and the document is saved to the correct folder, etc. It does everything I need done except one thing. Is there a way to allow the user that uploaded it to delete the document from the folder that it was saved to?

Thanks
swmckay 11 Nov, 2012
Can anyone assist? Thanks
emmexx 11 Nov, 2012
As a starting point you could read this FAQ.

Be carefule because the article code removes any file from a folder. You should add some code to check user and file names.

Bye
maxx
Max_admin 12 Nov, 2012
Hi,

This will be tricky, you can simply update the file name associated with your user in the database but leave the file on the disk intact, or get the file name before its updated and delete it using "unlink" function.

<?php
$path = "FULL PATH HERE";
unlink($path.'file_name');
?>


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 13 Nov, 2012
Hi swmackay,

Please also see this FAQ which talks about images but would apply to any uploaded file.

Bob
swmckay 08 Dec, 2012
Thank you all. I have the path in place and called the file that needs to be unlinked. I tried using curly brackets for the called field/file name but no luck. How would I populate 'file_name' with the a particular file within the UNLINK section?

Thanks again.
GreyHead 08 Dec, 2012
Hi swmackay,

Assuming that you have put the file name into the form in a hidden array with the name 'file_name' then it will be in $form->data['file_name'] after the form is submitted. This code should then delete it:
<?php
jimport('joomla.filesystem.file');
$path = JPATH_SITE.'some_path/';
$file =& $form->data['file_name'];
JFile::delete($path.$file);
?>

If you aren't loading the file name in this way you'd need to adapt the code to suit.

Bob

PS You can't use the curly brackets {file_name} with PHP.
swmckay 09 Dec, 2012
PRESTO!!!

Thank you guys so much!
ttomljen 13 May, 2013
sorry if this is offtopic to this section, but this is the nearest I could find:

is it possible to save uploaded files do a database so that users can review/change them(with DB record loader) at a later date?
Upload to a folder works fine, but I would also need to have a database record of it.
GreyHead 13 May, 2013
Hi ttomljen,

Please see this FAQ - is that what you need?

Bob
ttomljen 13 May, 2013
Thanks, but I read these instructions.

How to store the link of the uploaded document to a database.

I tried to save via classic DB save option but I'm getting nothing in the database but the file successfully uploads to the server.

Debugging of upload fields gives me
Array
(
     [hr_verzija_prijedloga] => Array
         (
             [name] => 20130513183854_test1111.txt
             [original_name] => test1111.txt
             [path] => / my_path/components/com_chronoforms/uploads/ZCI_2/20130513183854_test1111.txt
             [size] => 0
             [link] => http://my_web_page/components/com_chronoforms/uploads/ZCI_2/20130513183854_test1111.txt
         )


I would like to value [link] stored in the database.

After that I wanted via DB Record Loader display existing documents and give users the ability to update documents.

Thanks.
GreyHead 14 May, 2013
Hi

Please try adding a Custom Code action after the Upload Files action and before the DB Save action with code like this:
<?php
$form->data['file_link'] = $form->data['hr_verzija_prijedloga']['link'];
?>
but replace 'file_link with the name of the column in your table.

Bob
ttomljen 15 May, 2013
Thanks for the reply.

your answer gave ma a good guideline, I did some tweaking and here is my code I used to save document link into the database.
Hope someone else can use it...


<?php
$form->data['file_link'] = $form->data[_PLUGINS_][upload_files][field_name][link];
?>


In my form I added a custom element which gives user the overview of already uploaded documents.
Here is the code:


<?php
   $user = &JFactory::getUser();
   $form->data['cf_user_id'] = $user->id;
   $database = JFactory::getDBO();
   $database->setQuery("SELECT field_name FROM my_table WHERE cf_user_id = {$user->id}");
   $data = $database->loadAssoc();
   if(strlen($data['field_name']) > 1)
   {
      echo "<a href='".$data['field_name']."'>".$data['field_name']."</a>";
   }
   else
   {
      echo "<p>No document.</p>";
   }
This topic is locked and no more replies can be posted.