Forums

Link to attached file?

Baka 10 Oct, 2007
Hi, It turns out Chronoforms actually does way more with attached files than I need it to. Basically, I'm trying to implement a change whereby the table stores a url link to the attached file, which is also emailed rather than emailing the file itself.

This would make it easier for me to add submitted content to my site by just being able to copy and paste the URL rather than having to find it.

I've added a hidden field to the code, and to the table but now I need it to receive the value of the path to the uploaded file('$path'maybe?). I'm assuming this needs to be placed into the post email Submit section of the code tab?

I'm pretty much a newb at PHP, but I love a challenge. I've been looking at numerous PHP tutorials but I'm well and truly stuck.


Great component by the way, it's kept me entertained for hours!<br><br>Post edited by: Baka, at: 2007/10/10 08:20
Max_admin 10 Oct, 2007
Hi Baka,

Lets try this hack, at line 241 of chronocontact.php, find :
if ( $uploadedfile ) {
                        $attachments[$allowed_s2[0]] = $uploadedfile;
					}


then add this line below it :

$_POST[$allowed_s2[0]] = $mosconfig_live_site."/components/com_chronocontact/upload/".$uploadedfile;


Does this work ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Baka 10 Oct, 2007
Thanks for the quick response!

That code works perfectly. All I needed to do was remove the final "/" due to the way I have $mosconfig_live_site written.

Unfortunately I've run into another snag. Since I need users to be able to directly from the link even if not logged in, I noticed it was giving a 403 Forbidden error when an attempted download was made.

I CHMOD'd the folder from 600 to 755, but all new uploaded files are automatically set to 600.

I'm going to look for a way to CHMOD the new file to 755 on upload by playing around with the chmod() Function and post my results.

Thanks again, this is a fantastic component!
Baka 10 Oct, 2007
Success!

After adding the line "chmod($uploadedfile,0755);" the code changed from the original:


if ( $uploadedfile ) {

                        $attachments[$allowed_s2[0]] = $uploadedfile;

                    }


if ( $uploadedfile ) {
                        $attachments[$allowed_s2[0]] = $uploadedfile;
						chmod($uploadedfile,0755);
					}
					$_POST[$allowed_s2[0]] = $mosconfig_live_site."/components/com_chronocontact/upload".$uploadedfile;



I hope someone else finds this useful!


Thanks again,

B.
Max_admin 10 Oct, 2007
Excellent!! Thanks for sharing it๐Ÿ™‚

Sincerely,

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
payotte 17 Oct, 2007
Hello,

This is also what I'm trying to do.
I've tried modifiying the file as described, but I guess something is missing.

I already have a field in the HTML template that sends the name of the file, which is <?php echo $_FILES['photo']['name']; ?>

How should I modify it, so that it shows the whole name of the uploaded picture? I don't really need the absolute path, just the file name along with the date+hour+min+sec that Chronoform prepends when it uploads the file.

Regards,

P
GreyHead 17 Oct, 2007
Hi Payotte,

Have you tried <?php echo $uploadedfile ?> ??

Bob
Max_admin 18 Oct, 2007
Hi, at the last line of the hack, just remove this piece :

$mosconfig_live_site."/components/com_chronocontact/upload".
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
payotte 09 Nov, 2007
Hi,

I put <?php echo $uploadedfile; ? > in my template and it works well, and I could live with it, but maybe there's something else you could suggest.

This is the text result I get in the email:
/home/xxxxx/public_html/submit/components/com_chronocontact/upload/20071108211036_2007_09_16-01_pierre1.jpg

Is there any way to modify the above php line so that only the filename appears, withoug the full path? (20071108211036_2007_09_16-01_pierre1.jpg in this case)

If not, I can run a batch to strip it upon arrival I guess.

It's really a great component.

Tx
Max_admin 09 Nov, 2007
Hi payotte,

What about the latest fix above ? it will fix that for you if you can do it.

Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
payotte 19 Nov, 2007
It finally worked!
I had to set permissions to the upload folder to 777 though.
Is that a problem?
I don't intend to keep stuff there anyway.

P
payotte 20 Nov, 2007
Dang.
It isn't working anymore.
I tried a lot of variations of your hack just in case, with no success.This is frustrating, because I remember it working at least once.

Here is the code I currently have; can you tell me if it's exactly as it should be? I'm also including the html template, as maybe the problem is there.
if ( $uploadedfile ) {
$attachments[$allowed_s2[0]] = $uploadedfile;
}
$_POST[$allowed_s2[0]] = $uploadedfile;
}

html:
<td><?php echo $uploadedfile; ? ></td>
To resume, I want the name of the file as it is in the upload folder (with numbers prepended), without the whole path.

One last thing: I'm using Dreamweaver as my PHP editor and I notice it adds empty lines. Any other editor you would recommend?

Regards

P<br><br>Post edited by: GreyHead, at: 2007/12/04 17:40
payotte 22 Nov, 2007
Spent another 4 hours on this...
Still not working.

Maybe Baka or you could help me out in a simpler way:
Could you send me the chronocontact.php already modified in that way?

Basically, if it works on your side it will greatly help me isolate the problem on my side.

Regards,

P
Max_admin 22 Nov, 2007
Hi,

What do you get in the email now ? do you have the email setup to be a template of fields names ?

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
payotte 22 Nov, 2007
Hi,

This is the part of my HTML template that gets the results:
("photo" is the field name for the upload in the form)

<td><?php echo $_FILES['photo']['name']; ?></td>
<td><?php echo $uploadedfile; ? ></td>

This is what I get back for these two:
pierre1.jpg
and
/home/myuser/public_html/submit/components/com_chronocontact/upload/20071121121053_pierre1.jpg

This is what I want to get : 20071121121053_pierre1.jpg

Any help appreciated.

Regards,

Pierre
GreyHead 22 Nov, 2007
Hi Pierre,

Try
<?php echo basename($uploadedfile); ?>
That should just give you the piece that you want.

Bob
payotte 22 Nov, 2007
Yes!!

I kiss you๐Ÿ˜‰

Regards,

P
boxcarmib 22 Jan, 2008
Hi.
I'm trying to doing something similar, but not having much success.
I'm wanting to retrieve the filename (with it's timestamp) in a second chronoform called from the first (where the file is uploaded).

i've applied the hack, which to my way of understanding, should now included the filename in the $_POST sent to the 2nd chronoform.

i call the 2nd chronoform with the following:

index.php?option=com_chronocontact&chronoformname=goodLuckAdPhotoReceived

in the "submit URL:" field of the FORM URL's tab.

the file uploads okay, but i don't know how to retrieve it from the 2nd chronoform... must i do something else to have it post to the 2nd form?
GreyHead 22 Jan, 2008
Hi boxcarmib,

Please can you tell me what you want to do in more detail so that I can think through how best to link the parts. Do you want the first form to do anything (emails, data storage.???) If so then you'll need to use the Redirect URL (after processing) and not the OnSubmit URL (before processing).

And what do you want the second form to do? Will it always be fed by the first form? (May make a difference about how you tell it which database table to look in).

Bob
dniezby 22 Jan, 2008
What about adding this line of code to your template instead of modifying the core php file of the component.


<div><strong>Link to file: </strong><a href="http://www.yoursite.com/components/com_chronocontact/upload/{fieldname}"</div>


I'm not sure what you'd need to chmod...Maybe 755 but I don't know if you can just chmode the upload/ directory or if you have to chmod the files on the way up...<br><br>Post edited by: dniezby, at: 2008/01/22 05:25
boxcarmib 22 Jan, 2008
hmmm... i thought i had replied to GreyHead's post earlier, but it doesn't seem to be on the system. maybe i pressed the wrong button.

anyway, let me try it again.

i'm using a number of chronoforms, where each form passes on the information needed to the next form through $_POST.

in order to do this, i put the url of the second chronoform (cf#2) in the OnSubmit URL field of the URL tab in the first chronoform (cf#1). This seems to work fine, in that all input fields of cf#1 are available in cf#2 through $_POST. (I had tried putting the url of cf#2 in the Redirect URL field, but there was nothing in $_POST passed on).

what i'm trying to do in this specific case, is allow the user to specify a caption and some other information in cf#1 and then upload an image. Then the user is sent to cf#2 where the image they uploaded is scaled to a standard size and the caption is added, and the user is asked to approve the layout. that's the reason i need the filename of the image that was uploaded in cf#1 when i'm in cf#2.

as it stands, i don't want cf#1 to do anything except accept the upload, and pass the uploaded filename and the rest of the information in the fields off to cf#2.

cf#2 will only ever be fed by cf#1.

i hope this makes sense.
GreyHead 22 Jan, 2008
Hi boxcarmib,

The uploaded file info is passed in $_FILES so you could try looking in that in your second form - I think the data should be passed just like the $_POST data.

The problem that you may have is that you've bypassed all of ChronoForms file handling code so that you'll need to make sure that the file is saved somewhere.

The alternative you could use is to save the data into the database from cf#1 and pass the database table name and record id to form cf#2 through the ReDirect URL.

Both methods have plusses and minuses.

Bob
boxcarmib 23 Jan, 2008
thanks for all your help bob. my problem was confusion about the way chronoforms work. with your helpful comments i think i understand a lot better.

on reflection i think i'll try using the addCustomHeadTag() call as displayed in the faq under "How do I display a 'Thank you' page?"

i'm pretty much a newbie at joomla and chronoforms, but it would appear that i can drop any code i want to in the "On Submit code - after sending email" field... INCLUDING a complete new form.

the cool thing is that the context of the first page is preserved and it allows me to 1) take advantage of all the chronoforms processing features and 2) add whatever hidden input types i want to pass on the data collected from the initial form.

am i missing something... is this gonna turn around and bite me in the butt?

i've noticed in some of the forums people asking for chronoforms to provide for the ability of one form to call another... much in the way the addCustomHeadTag() works. But isn't this exactly what addCustomeHeadTag() does?

Anyway, thanks again for all the help, and particularly for the speed with which my queries were answered... for that reason alone... best joomla extension i ever bought.
GreyHead 23 Jan, 2008
Hi boxcarmib,

I think that perhaps it's time to try and draw a diagram to set out how ChronoForms works - I'll need to find some time and a cold towel or two!

You could put a complete form in the 'On Submit' box, but probably better not to! Just process the data and send it to another page (which could be another ChronoForms form).

There are various ways of passing data between pages - including $_POST & $_GET variables, sessions, cookies and saved data. Which is 'best' depends on the context.

If you want to pass some information about an image then you could pack it up in an array like $image = array('name'=>'thisimage.jpg', 'width'=>'200', ... etc. ) add pass this on. But given that you may want to handle the same image some other way in the future it might be better to add it into a database table and pass the record reference to the second form.

addCustomHeadTag() just allows you to add a tag into the header section of the page - in this case a redirect tag. It's not a very elegant way of moving between pages, it worked for Beata because she wanted to show a Thank You page for a few seconds before redirecting.

Bob


Bob
microdave 24 Sep, 2008
Does this method also apply to the version that is made for joomla 1.0
Max_admin 24 Sep, 2008
Hi, yes it should be the same!

Regards

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.