Re: How to upload a file using a form
I'm confused as to Notepad. Is that the HTML on the form or on the page?
How to upload a file using a form
Collapse
This topic is closed.
X
This is a sticky topic.
X
X
-
Re: How to upload a file using a form
Just link it the normal way with the hyperlink button. The way it works is that they right lick on the link and then choose "save target as" to their computer. Thats it.
Gald all is well with the form.
Cheers-
Andy
Leave a comment:
-
Re: How to upload a file using a form
Thank you so much. It was about midnight last night when I was working on that and I was getting so frustrated...then I forgot my password into the forums and got locked out.
Anyway, I forgot that I accidently put the script in the thank you page, so I just deleted it and it works beautifully. I had just followed the tutorials above (but when you're tired, sometimes you skip a step and have to go back...then things get messed up!)
By the way, can you tell me how to have a link on the page that will allow the user download a file (i.e., word document). I'm sure it's easy, but I've fiddled with it this morning and it's not working.
Thanks again!
Leave a comment:
-
Re: How to upload a file using a form
Will'smom,
You have placed php code inside the thank_you.html page and that is why it is showing up. The action of the form is set to uploadaction.php and this is where the php code should be. At first glance, I would say simply delete any php code that you have placed in the thank_you.htmll page and it should be ok.
First- can you give the url of the instructions you followed to get this far?
We will take a look at it and then go from there.
Andy
Leave a comment:
-
Re: How to upload a file using a form
Could someone let me know what I did wrong? I got everything to work right except on the thank you page, a bunch of script appears at the very top (from the uploadaction.php part).
Everything works except that (the form, the file upload, the thank you page... ). I don't know anything about code, so I don't want to start messing with what I don't know how to read.
www.TreasuredXpressions.com/Order.html
which leads to www.TreasuredXpressions.com/thankyou_page.html
Thanks in advance...
Leave a comment:
-
Re: How to upload a file using a form
I was able to set up a dwnload link. The only problem is the file begins to play once dwnloaded. The file I have is a Flash MC file to be used for websites. Is there a way to have it dwnload onto the users desktop as a file to be used later?
Leave a comment:
-
Re: How to upload a file using a form
Why don't you use ABVFP ? it will take care of as many uploads you like, and will also attach the files to the email that you will receive. It also allows autoresponder, multiple choice dropdowns and a lot more. And, if you want, it will also store the form info in a database.
Leave a comment:
-
Re: How to upload a file using a form
AHA!
I think i've got it working now, didn't notice the form tony had posted, once I edited the links and updated the form field names it works a treat.
Thanks tony et all.
Leave a comment:
-
Re: How to upload a file using a form
Originally posted by navaldesign View PostUPLOADING MULTIPLE FILES
Ok, here is a script for uploading two files. The same structure can be adopted for multiple files, repeating the blocks as they appear in the script.
Please note that this script follows the same logical structure of the single upload field one, but with some additional checking: f.e. the size error checking has to be done for both upload fields BEFORE the script starts uploading. Then it has to check again, field by field, before it starts the real upload, otherwise you could have error headers sent out and the script broken, if f.e. one of the two fields is empty.
Please note that this is NOT what i would have used: a would have used a include file to minimise scripting. However, this would exceed the capabilities of the average user, as it would require more php files to be compiled and uploaded. This way instead, it is pretty straight.
<?php
// Receiving variables
@$email = addslashes($_POST['email']);
@$upload_Name = $_FILES['upload']['name'];
@$upload_Size = $_FILES['upload']['size'];
@$upload_Temp = $_FILES['upload']['tmp_name'];
@$upload1_Name = $_FILES['upload1']['name'];
@$upload1_Size = $_FILES['upload1']['size'];
@$upload1_Temp = $_FILES['upload1']['tmp_name'];
// Validation for max file size
// Validation for the first file, if it exists. Repeat the block as many times as your upload fields.
if ($upload_Size>0)
{
if( $upload_Size >1000000)
{
//delete file
unlink($upload_Temp);
header("Location: error.html");
exit;
}
}
// Validation for the second file, if it exists. In the additional blocks, change the number 1 to 2 or 3 or ... n
if ($upload1_Size>0)
{
if( $upload1_Size >1000000)
{
//delete file
unlink($upload1_Temp);
header("Location: error.html");
exit;
}
}
// Uploading the first file, if it exists. Repeat as many times as your upload fields.
if ($upload_Size>0)
{
$uploadFile = "uploads/".$upload_Name ;
@move_uploaded_file( $upload_Temp , $uploadFile);
chmod($uploadFile, 0644);
$upload_URL = "http://www.yourdomain.com/uploads/".$upload_Name ;
// Uploading the second file, if it exists.
if ($upload1_Size>0)
{
$uploadFile = "uploads/".$upload1_Name ;
@move_uploaded_file( $upload1_Temp , $uploadFile);
chmod($uploadFile, 0644);
$upload1_URL = "http://www.yourdomain.com/uploads/".$upload1_Name ; // You must change the number 1 to 2 or 3 or whatever in the additional blocks
}
//Sending Email to form owner
$mailto = "youremail@yourdomain.com";
$mailsubj = "Enter Your Subject Here";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form :\n";
while (list ($key, $val) = each ($HTTP_POST_VARS))
{
if ($key!="submit")
{
$mailbody .= "$key : $val\n";
}
}
$mailbody .= "File Link 1: $upload_URL\n"; // This line is to add the link to the first file. Repeat as many times as your upload fields
$mailbody .= "File Link 2: $upload1_URL\n"; // This line is to add the link to the second file.
$mailbody .= "If any link is broken, please copy and paste it in your browser's address bar\n";
mail($mailto, $mailsubj, $mailbody, $mailhead);
// Autoresponder: if you don't want the autoresponder, delete this and the following 7 lines in Green color
if ($Copy != "")
{
$mailto = $email;
$mailsubj = "Copy of the info you Submitted";
$mailhead = "From: put your site or company name here: \n";
mail($mailto, $mailsubj, $mailbody, $mailhead);
}
header("Location: thankyou_page.html");
?>
As always change the part s in blue to be your own details. The blocks can be repeated as many times as you want, to include as many upload fields as you want. The fields in the form should be named: upload, upload1, upload2, upload3, ...... upload(n) where n is the last field.
You can test the form here. If you tick the small bottom check box, you will receive a copy email of the info submitted, with the file kinks, so you can check yourself how the script works.
Hi, Having some trouble getting this script to run, the single upload version works fine, however this one fails on the rediret, both on the error redirect and the thank you one.
I get the following message:
Parse error: syntax error, unexpected $end in /home/gopriva1/public_html/test/uploadaction.php on line 93
Yet if I switch back to the single upload version all works fine. Am I missing sometihng?
Many thanks
Chris
Leave a comment:
-
Re: How to upload a file using a form
Have a look at http://it.php.net/manual/en/function...oaded-file.php
Leave a comment:
-
Re: How to upload a file using a form
Originally posted by navaldesignNow, as for your script, it seems correct (apart the part that has been modified by this forum's text editor, pursing links even when it shouldn't)
Does the script get to upload the files and send the mail ? or doesn't it ?
And yes, you can write the data in a file on your server. I simply never use this method, as i prefer storing all the info in a database. But this exceeds the tutorial's purposes.
Yes, it uploads the file and sends the email containing the links to the photos. I've spent countless hours trying to get a php form to work... got yours to work in 10 minutes. Thanks... I'll take a look at the php site. I didn't even realize you are in Italy!
Leave a comment:
-
Re: How to upload a file using a form
Yes, there are scripts that will make an incremental saving. Since this is only a forum for our members, not for programming talk, we do no go so deep in the scripts that we post. Go in php.net and see the upload function parametres, i beleive there are some examples of how to make incremental save.
Now, as for your script, it seems correct (apart the part that has been modified by this forum's text editor, pursing links even when it shouldn't)
Does the script get to upload the files and send the mail ? or doesn't it ?
And yes, you can write the data in a file on your server. I simply never use this method, as i prefer storing all the info in a database. The database approach allows for research features, dynamic resizing of the images, realtime registration of the users, anyminute editing possibilities, payment followup, etc. But this exceeds the tutorial's purposes.
Leave a comment:
-
How To Prevent Files From Being Overwritten
I know in frontpage you can set folder properties so file uploads can not overwrite existing files. If a uploaded did this the form would redirect them to an error page stating to rename the file and try again.
I am trying to get away from using frontpage, so I used your code from above to modify my form. I had to combine some of the validation to get it to work... I kept getting an Parse error: parse error, unexpected $ in the last line.
However, I'm affraid that some people may have the same file name when uploading photos... Is their something I can add to the script to prevent overwriting and a possible error page telling them how to correct the problem. Or even a number being automaticly added to the file name.
Is it possible to send the information to a file on the server too? Thanks for the help in advance. I'll send you a digital music coupon.
Here is my form:
Code:
<?php
// Receiving variables
@$email = addslashes($_POST['email']);
@$upload1_Name = $_FILES['upload1']['name'];
@$upload1_Size = $_FILES['upload1']['size'];
@$upload1_Temp = $_FILES['upload1']['tmp_name'];
@$upload2_Name = $_FILES['upload2']['name'];
@$upload2_Size = $_FILES['upload2']['size'];
@$upload2_Temp = $_FILES['upload2']['tmp_name'];
// Validation for max file size
if ($upload1_Size>0)
{
if( $upload1_Size >1000000)
{
//delete file
unlink($upload1_Temp);
header("Location: error.html");
exit;
}
$uploadFile = "uploads/".$upload1_Name ;
@move_uploaded_file( $upload1_Temp , $uploadFile);
chmod($uploadFile, 0644);
$upload1_URL = "<A href="http://www.capitalareaapartments.com/uploads/".$upload1_Name">http://www.capitalareaapartments.com/uploads/".$upload1_Name ;
}
if ($upload2_Size>0)
{
if( $upload2_Size >1000000)
{
//delete file
unlink($upload2_Temp);
header("Location: error.html");
exit;
}
$uploadFile = "uploads/".$upload2_Name ;
@move_uploaded_file( $upload2_Temp , $uploadFile);
chmod($uploadFile, 0644);
$upload2_URL = "<A href="http://www.capitalareaapartments.com/uploads/".$upload2_Name">http://www.capitalareaapartments.com/uploads/".$upload2_Name ;
}
//Sending Email to form owner
$mailto = "sales@capitalareaapartments.com";
$mailsubj = "Ad Listing";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form :\n";
while (list ($key, $val) = each ($HTTP_POST_VARS))
{
if ($key!="submit")
{
$mailbody .= "$key : $val\n";
}
}
$mailbody .= "upload1: $upload1_URL\n";
$mailbody .= "upload2: $upload2_URL\n";
mail($mailto, $mailsubj, $mailbody, $mailhead);
header("Location: orderconfirm.htm");
?>
Thank you for the code, it was the only site that explained it perfectly!!!
-Tony
Leave a comment:
-
Re: How to upload a file using a form
A progress bar requires the use of Javascript and AJAX together with PHP. I have only found one script on the net about this, but seems that the relative download link is no more functioning.
Leave a comment:
Leave a comment: