By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

uploading a file with php

P: 2
this is probably a total newbie question, but i can seem to figure it out.
when i run this code it gives me this error:
Undefined index: work in FILENAME on line 3... which is the file-to-be-uploaded name.

i copied this from php.net, so i thought it should work. then i copied the simpler code from w3 schools, and that gave me the same error. but, here is my html and php:

[HTML]<form action="process.php" method="POST">
Picture: <br>
<input type="hidden" name="MAX_FILE_SIZE" value="25000" />
<input name="work" type="file" >
<br><br>
<input type="submit" value="Submit">[/HTML]

[PHP]<?php
$target_path = "/uploads/";
$target_path = $target_path. basename( $_FILES['work']['name']);

if(move_uploaded_file($_FILES['work']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['work']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>[/PHP]

thanks in advance to anyone who stoops to answer my easy question!

oh, also, it might help to know that i am using brinkster, and their php.ini file does not allow me to do many things (like send email). which sucks for me, since i obviously am not the most knowledgable in php. also, this is a page for someone else, so moving the website from brinkster to another server is not an option! :)
Oct 27 '08 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
You haven't given the form's enctype.

Expand|Select|Wrap|Line Numbers
  1. <form ... enctype="multipart/form-data">
  2. ...
  3. </form>
  4.  
Oct 27 '08 #2

P: 2
You haven't given the form's enctype.

Expand|Select|Wrap|Line Numbers
  1. <form ... enctype="multipart/form-data">
  2. ...
  3. </form>
  4.  

thank you so much markus! that was it! you sir, are most excellent! have a wonderful week!
Oct 27 '08 #3

Markus
Expert 5K+
P: 6,050
thank you so much markus! that was it! you sir, are most excellent! have a wonderful week!
Aha! Well thank you for such a warm thank you!

See you around.

Markus.
Oct 27 '08 #4

zabsmarty
P: 25
change this
<form action="process.php" method="POST">

into
<form enctype="multipart/form-data" action="process.php" method="POST">
Oct 28 '08 #5

Markus
Expert 5K+
P: 6,050
change this
<form action="process.php" method="POST">

into
<form enctype="multipart/form-data" action="process.php" method="POST">
Ok, are you just taking my answers and putting them into different words?
Oct 28 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.