Forums

problem while uploading a file

firestarter 09 Dec, 2009
Hi, I will use an upload section in my form and when the user upload his files, a new folder will be created with his name and the file will be saved under this directory each time he makes a new upload. Actually I found a free joomla plugin to do that but when I embed this plugin like {upload}into my chrono form it almost does the trick. when the user hit to the upload button a new directory created with his username but the form gives the error "not allowed to access the URL". how can I figure this out? any help appreciated, thanks.
GreyHead 09 Dec, 2009
Hi firestarter,

Could be that you have form tags inside the form and that's not allowed. Hard to tell without seeing the page.

Fredrik 'nml375' posted a way of doing exactly this in ChronoForms a day or so ago in the forums here.

Bob
firestarter 10 Dec, 2009
Hi Greyhead,

I have checked Fredrik's last posts but I can not find any solution to my problem. Yes, the plugin includes Form tags and I think i need to get rid of these form tags to solve my problem but I dont know how to do that. I might use a javascript or something or write a php code on after submit area from the current upload plugin code but there should be an easier way i suppose and I really need guidance on that. thanks.
GreyHead 10 Dec, 2009
Hi firestarter,

Please see this thread. It was an old post of Fredrik's with a recent reply that I'd remembered.

Bob
nml375 10 Dec, 2009
Hi,
I might add that the post linked assumes you are using a "trivial" file form input. My personal experience is that using fancy background uploaders require lots of work to integrate at all with ChronoForms.
I'm not going to go into all the gory stuffs of this, but simply recommend that you use a simple <input type="file" ...> input along with the instructions in the post linked.

/Fredrik
firestarter 11 Dec, 2009
Hi,

I'm in progress to achieve what I want. I am able to create folder named with logged-in user's username but not able to save the uploaded file into that folder. my code is below just trial for now.

Form HTML:
<div class="form_item">
  <div class="form_element cf_fileupload">
    <label class="cf_label" style="width: 150px;">Click Me to Edit</label>
    <input class="cf_fileinput cf_inputbox" title="" size="20" id="file_0" name="userfile" type="file" />
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Submit" name="button_1" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>


On Submit code - after sending email:
<?php

$filename = $_FILES['userfile']['name']; 
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

$user = & JFactory::getUser();
		$username = $user->username;
$guest = $user->guest;
if ($guest){
echo "please login";
} else {

}
	
$destination = "../files/";

if(!is_dir('$username') && !$guest)	{
	@mkdir ("$destination/$username", 0777);
}

if(move_uploaded_file($_FILES['userfile']['tmp_name'],$destination . $filename))
         echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>';
      else
         echo 'There was an error during the file upload.  Please try again.';

?>


When I upload a jpeg, I get the error "There was an error..." so any comment on that. thanks.
nml375 12 Dec, 2009
Hi,
I'm out of town and using a mobile client,so I'll be rather brief..

By the time we get to the on submit before/after email, ChronoForms has already handled the file upload.. Which among other things involves moving the file from the temporary storage to wherever you told chronoforms to put it, with whatever name you gave it using the $filename variable in the FIle Uploads tab settings...
As such, $_FILES does not give an accurate description of the uploaded files..

Since you are using a normal file input, why not just do as instructed on the linked post. Solves the ssue with a single line of code. You could rather easily incorporate your code to restore the submitted filename into that line of code as well..

/Fredrik
firestarter 14 Dec, 2009
it worked like a charm in the end. the mistake was mine. I forgot to add 'enctype="multipart/form-data"' to form tag attachment textbox. thanks for your support.
GreyHead 14 Dec, 2009
Hi firestarter,

Glad to hear that it's working.

Bob

PS ChronoForms does try to add the enctype for you but doesn't always succeed :-(
This topic is locked and no more replies can be posted.