This is a discussion on "uploading files using online forms" within the PHP Forum section. This forum, and the thread "uploading files using online forms are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
uploading files using online forms
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
uploading files using online forms
Hi all,
I have an online form, that I have written a php script for. However, this particular form has file upload fields, and i have no idea how to write script to actually get the files to upload. The webpage I have set up is: http://www.idrn.org/grantworkshopregistration.php The script is pasted below. I've been looking at various php sites, but really cant work this one out for myself. So essentially, what script to I need to add to my existing php? Also, I assume files will be uploaded to my ftp site, ftp.idrn.org, so how would I specify that? Does the html need to be changed in any way? Thanks for any help Mike <?php $recipient = "m.head@pcps.ucl.ac.uk"; $subject = "grantsmanship workshop application"; $message = "Title: " . $_POST['title'] . "\n"; $message .= "Name: " . $_POST['name'] . "\n"; $message .= "Position: " . $_POST['position'] . "\n"; $message .= "Postal: " . $_POST['postal'] . "\n"; $message .= "Email: " . $_POST['email'] . "\n"; $message .= "Telephone: " . $_POST['telephone'] . "\n"; $message .= "Justification: " . $_POST['justification'] . "\n"; $uploaddir = 'ftp.idrn.org'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); $sent = @mail($recipient, $subject, $message); header('Location: http://www.idrn.org/thankyou.php'); ?> |
|
|
|
|||
|
Re: uploading files using online forms
|
|
|||
|
Re: uploading files using online forms
It does help, but doesnt quite help enough!
I've looked through similar tutorials, but cant get the files to upload. |
|
|||
|
Re: uploading files using online forms
what errors are you getting when you try to move the files? The upload directory needs to be a directory with the appropriate write permissions assigned to it. Eg /uploads.
|
|
|||
|
Re: uploading files using online forms
Thats the thing, I dont get an error message!
The rest of the form submits fine, I receive the info in an email, the web page directs to the 'thank you for completing our form' end page. I've been told by my web host I can simply upload to the root directory of the ftp site. Everything else works. |
|
|||
|
Re: uploading files using online forms
ok so the forms input field should be something like;
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" /> <input type="file" name="userfile" maxlength="50"> and the form should be ; <form enctype="multipart/form-data" action="a_php_page.php" method="post" name='myForm'> Then you need to move the file to a directory using the following; move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name']); You will also need the directory to exist, something like /myUploadedFiles for example in your document root, which also needs to have the appropriate write permissions associated with it. Basically what happens is the file is uploaded using http from the form, this file is then saved in a temp directory (phpinfo() will tell you where it is) on the server so you then need to move it to the directory that you want to save it in. You should also really do a whole lot of checks on the file that you upload to a server to ensure it is what you think. Hope this helps if not post again and i'll post a full script to help get it sorted for you, good luck! Last edited by Gee Bee; Jul 22nd, 2006 at 07:53. |
|
|||
|
Re: uploading files using online forms
Thanks, I'll give that a go when i'm back at work on tuesday.
Cheers Mike |
|
|||
|
Re: uploading files using online forms
Nope, still infuriatingly it wont work, what am i doing wrong? (All other parts of the form submit information fine with no error messages at any point)
On the web page, for the file upload field i have <input type="hidden" name="MAX_FILE_SIZE" value="2000000" /> <input name="uploadfile1" type="file" id="uploadfile1" size="50"> For the form setup i have <form action="http://www.idrn.org/php/grantsmanshipscripttest.php" method=post enctype="multipart/form-data" name="registration" id="registration"> And php script pasted below: <?php $recipient = "m.head@pcps.ucl.ac.uk"; $subject = "grantsmanship workshop application"; $message = "Title: " . $_POST['title'] . "\n"; $message .= "Name: " . $_POST['name'] . "\n"; $message .= "Position: " . $_POST['position'] . "\n"; $message .= "Postal: " . $_POST['postal'] . "\n"; $message .= "Email: " . $_POST['email'] . "\n"; $message .= "Telephone: " . $_POST['telephone'] . "\n"; $message .= "Justification: " . $_POST['justification'] . "\n"; $uploaddir = 'ftp.idrn.org/uploads'; move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name']); $sent = @mail($recipient, $subject, $message); header('Location: http://www.idrn.org/thankyou.php'); ?> |
|
|||
|
Re: uploading files using online forms
You have an error with the $_FILES variable. The userfile in $_FILES['userfile'] should be the same as the name of the input that the file is being uploaded with ie, move_uploaded_file should be
move_uploaded_file['uploadfile1']['tmp_name'], $uploaddir . $_FILES['uploadfile1']['name']); |
![]() |
| Tags |
| uploading, files, using, online, forms |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| uploading files | Phixon | Flash & Multimedia Forum | 3 | Nov 14th, 2007 11:43 |
| uploading files | ziggi | PHP Forum | 8 | May 30th, 2007 20:16 |
| Uploading various image files | Paula | ASP.NET Forum | 1 | Oct 7th, 2006 20:39 |
| files not uploading | skyfire400 | Hosting & Domains | 1 | Mar 4th, 2006 18:30 |
| Uploading of files | gwx03 | Implemented Suggestions | 6 | Dec 24th, 2003 21:51 |