File Upload With Form to Specific Location

Permalink
I have one form on my site with a file upload on it that I need to be able to control where the file is being placed by the form. I have noticed that each time a file is uploaded with the same form, the file goes in a different location in the directory structure.

I need to be able to access that file that the C5 Form uploads to manipulate the data in that file with a program that isn't related to Concrete5, so it needs to be in a known location. If it helps to solve this problem, the person uploading the file can log in and have administrative rights to the site.

Thanks for any help.

sogren
 
JohntheFish replied on at Permalink Reply
JohntheFish
This is unfortunately the way the C5 file manager works. A few ideas, all slightly bodged:

1. Write your own upload code or get from a third party, so bypassing the C5 file manager.

2. After upload, in your code interrogate the file manager and write the location of the uploaded file somewhere that your external code/tool can read it from (like setting a pointer).

3. As 2, but copy the uploaded file from the file manager to your known location.

4. Write a C5 'tool' that returns the file or the location of the file from the c5 file manager. Let your external code read the location from that tool.

5. Write a C5 'tool' that streams the file from the c5 file manager. Let your external code read the file from that tool stream.
melange replied on at Permalink Reply
melange
Hi all,

I know this post is 5 years old hoping to get some follow up. Being a newbie to CC5 still working things out. I am wanted something on my site basically a button would be nice that allows visitors to upload content to the server. I am not wanting a specific location. I dont understand code or script so much yet to modify whats been posted as I dont understand it.
Any feedback would be appreciated

Thanks !!
pvernaglia replied on at Permalink Reply
pvernaglia
You can modify the form a bit so uploads are assigned to a fileset, then they would be all grouped together in the file manager. This snipet should point you in the right direction:

<?php
  // when uploading with a form
  function action_file_upload()   {
    Loader::library("file/importer");
    $fi = new FileImporter();
    $newFile = $fi->import($_FILES['fileName']['tmp_name'],
    $_FILES['fileName']['name']);
    // add file to file set      
    Loader::model('file_set');
    $fs = FileSet::createAndGetSet('FILE_SET_NAME', FileSet::TYPE_PUBLIC, 
    $uID = false);
    $fsf = $fs->addFileToSet($newFile);   
  }
?>http://www.weblicating.com/c5/cheat-sheet/...
CaptainPanda replied on at Permalink Reply
Hi I know this is a rather old post but I need some help with this too.

This code is working fine, but how can I edit it to give my file a custom name when I upload it?

That is to say, regardless of what the file is named on the client computer when it is uploaded I would like it to be named "myFileName" that is set in the controller file for the page im working on.
CaptainPanda replied on at Permalink Reply
Hi I know this is a rather old post but I need some help with this too.

This code is working fine, but how can I edit it to give my file a custom name when I upload it?
jordanlev replied on at Permalink Reply
jordanlev
As John mentioned, C5 doesn't provide built-in functionality to put files anywhere you want, but this functionality is relatively easy to do with plain old PHP code.

I recently had to make a "file upload" user attribute that adds a normal file upload control to the registration form:
http://c5blog.jordanlev.com/blog/2011/12/file-upload-attribute-for-...

I know that's not exactly what you're looking for, but it could probably serve as a good example of how to implement your own file upload functionality.

BTW, if this is just for one specific site, you'll be better off just coding your own contact form as a single_page (or as a custom block -- seehttps://github.com/jordanlev/c5_custom_contact_form... for some starter code). The form block is really complicated and the code is hard to untangle.