uploading files using online forms

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.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Jul 19th, 2006, 12:36
New Member
Join Date: Jul 2006
Location: London
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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');
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 19th, 2006, 13:13
Up'n'Coming Member
Join Date: Jan 2006
Location: East Sussex
Age: 27
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Re: uploading files using online forms

Check out this tutorial, should be of use

http://www.tizag.com/phpT/fileupload.php
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jul 20th, 2006, 12:46
New Member
Join Date: Jul 2006
Location: London
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jul 21st, 2006, 16:43
Up'n'Coming Member
Join Date: Jan 2006
Location: East Sussex
Age: 27
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jul 21st, 2006, 18:35
New Member
Join Date: Jul 2006
Location: London
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jul 21st, 2006, 21:14
Up'n'Coming Member
Join Date: Jan 2006
Location: East Sussex
Age: 27
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jul 22nd, 2006, 10:10
New Member
Join Date: Jul 2006
Location: London
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: uploading files using online forms

Thanks, I'll give that a go when i'm back at work on tuesday.

Cheers
Mike
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jul 27th, 2006, 10:13
New Member
Join Date: Jul 2006
Location: London
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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');
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Jul 29th, 2006, 10:52
Up'n'Coming Member
Join Date: Jan 2006
Location: East Sussex
Age: 27
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
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']);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
uploading, files, using, online, forms

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 15:45.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42