Simple File Upload Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Simple File Upload Form

Post by nickman013 »

Hey,

I need help creating a simple, I mean simple photo upload form.

I just need it to make sure the file is a image, and it is under 5 megabytes.

Thank You!
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

You should get a plenty of code snippets for file upload and search in this forum as well.
File type and size come as natural attributes for INPUT type file
Look here for basic information
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

ok

i have made the form, now i just need to make a upload script for the file (which i dont know how to do), and a email script (which i do know how to do)

my form is:

Code: Select all

<form action=test.php method=post>
<table length=50 border=1>
<tr BGCOLOR=#A9A9A9>
<td>Your Name:</td><td><input type=text name=yourname length=20></td></tr>
<tr BGCOLOR=#A9A9A9>
<td>Muot's Name:</td><td><input type=text name=muotsname length=20></td></tr>
<tr BGCOLOR=#A9A9A9>
<td>Muot's Picture:</td><td><input type=file name=img[] size=30></td></tr>
<tr BGCOLOR=#A9A9A9>
<td>Muot's Nickname:</td><td><input type=text name=muotsnickname length=20></td></tr>
<tr BGCOLOR=#A9A9A9>
<td>Muot's Age:</td><td><input type=text name=moutsage length=3></td></tr>
<tr BGCOLOR=#A9A9A9>
<td>Muot's Location:</td><td><input type=text name=muotslocation length=20></td></tr>
<tr BGCOLOR=#A9A9A9>
<td>Muot's Sex:</td><td><input type=radio name=muotssex value=MALE>Male &nbsp; <input type=radio name=muotssex value=FEMALE>Female</td></tr>
<tr BGCOLOR=#A9A9A9>
<td>Muot's Weight:</td><td><input type=text name=muotsweight length=3></td></tr>
<tr BGCOLOR=#A9A9A9>
<td>Muot's Height:</td><td><input type=text name=muotsheight length=5></td></tr>
<tr BGCOLOR=#A9A9A9>
<td valign=top>Muot's Status:</td><td><textarea name=muotsstatus rows=10 cols=17 wrap=physical></textarea></td></tr>
<tr BGCOLOR=#A9A9A9>
<td valign=top>About This Muot:</td><td><textarea name=aboutthismuot rows=10 cols=17 wrap=physical></textarea></td></tr>
<tr BGCOLOR=#A9A9A9>
<td align=center colspan=2>
<input type=submit value="Submit the Muot!">
</td>
</tr>
</table>
</form>
I know how to make the email script but is there a way to get the URL of the submitted picture?

So What I need to get done:
1. Simple upload script that just has path, any image type, and max size to be 5MB, also the smalled and easiest script possible. Very BASIC!
2. Get a link of the submitted picture.


Thank You
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

i found the script i was looking for , it works beatifuly!

the script is

Code: Select all

<?
// Where the file is going to be placed 
$target_path = "/home/muot/public_html/pages/muotreport/submitted/";

/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];
$target_path = "/home/muot/public_html/pages/muotreport/submitted/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
?>
thank you everyone who helped!
Post Reply