PHP and uploading files

N

Nonee

Hello all,

Ok ok, I have searched the internet extensively and I cannot find
the answer to this. I have found many answers but none of which that
work. I am running an apache server on my end, local for testing, and
I have wrote a php page that will accept a file to be uploaded. See
below.


<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<span class="smHeader">Choose a file to upload: </span></td>
<td><input name="uploadFile" type="file" />

Then on the added.php file that I post to, I have

if ($_POST["password"] == "") // Blank for now so I don't have to
type it everytime. Btw, is this secure???
{
$last = $_POST["last"];
mkdir("C:\\apache2triad\\htdocs\\condolences\\".$last);
//local file will be replaced when posted
echo "Made it! ". $_FILES['uploadFile']['name'];
if ( move_uploaded_file ($_FILES['uploadFile']
['tmp_name'],"../uploads/{$_FILES['uploadFile'] ['name']}") )
{
print '<p> The file has been successfully uploaded
</p>';
}
else
{

// ...EXCLUDED. JUST USED FOR TESTING THE ERROR
}
}

?>

Notice the echo "Made it!".$files line. It posts the made it part but
nothing for the file. Now I created a ../uploads folder (which is in
the root, correct? I never could get the . or .. stuff right). But
it just will not work. Is it because I am running the server local?
Shouldn't be... Or is it something with the php.ini config or apache
config? Please help. This is really annoying...

Thanks,

Josh
 
H

Hywel Jenkins

Hello all,

Ok ok, I have searched the internet extensively and I cannot find
the answer to this. I have found many answers but none of which that
work. I am running an apache server on my end, local for testing, and
I have wrote a php page that will accept a file to be uploaded. See
below.


<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<span class="smHeader">Choose a file to upload: </span></td>
<td><input name="uploadFile" type="file" />

Then on the added.php file that I post to, I have

if ($_POST["password"] == "") // Blank for now so I don't have to
type it everytime. Btw, is this secure???
{
$last = $_POST["last"];
mkdir("C:\\apache2triad\\htdocs\\condolences\\".$last);
//local file will be replaced when posted
echo "Made it! ". $_FILES['uploadFile']['name'];
if ( move_uploaded_file ($_FILES['uploadFile']
['tmp_name'],"../uploads/{$_FILES['uploadFile'] ['name']}") )
{
print '<p> The file has been successfully uploaded
</p>';
}
else
{

// ...EXCLUDED. JUST USED FOR TESTING THE ERROR
}
}

?>

Notice the echo "Made it!".$files line. It posts the made it part but
nothing for the file. Now I created a ../uploads folder (which is in
the root, correct? I never could get the . or .. stuff right). But
it just will not work. Is it because I am running the server local?
Shouldn't be... Or is it something with the php.ini config or apache
config? Please help. This is really annoying...

Is your form set up correctly - enctype="multipart/form-data"

The name of the file won't be in $_POST, either. It will be in
$_FILES["FieldName"]["name"]
 
N

Nonee

Thank you very much! I did try the multipart thing and that didn't
work last time. Now it does. Have NO idea as to why... lol.

Thanks for the help!

-Josh

Hello all,

Ok ok, I have searched the internet extensively and I cannot find
the answer to this. I have found many answers but none of which that
work. I am running an apache server on my end, local for testing, and
I have wrote a php page that will accept a file to be uploaded. See
below.


<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<span class="smHeader">Choose a file to upload: </span></td>
<td><input name="uploadFile" type="file" />

Then on the added.php file that I post to, I have

if ($_POST["password"] == "") // Blank for now so I don't have to
type it everytime. Btw, is this secure???
{
$last = $_POST["last"];
mkdir("C:\\apache2triad\\htdocs\\condolences\\".$last);
//local file will be replaced when posted
echo "Made it! ". $_FILES['uploadFile']['name'];
if ( move_uploaded_file ($_FILES['uploadFile']
['tmp_name'],"../uploads/{$_FILES['uploadFile'] ['name']}") )
{
print '<p> The file has been successfully uploaded
</p>';
}
else
{

// ...EXCLUDED. JUST USED FOR TESTING THE ERROR
}
}

?>

Notice the echo "Made it!".$files line. It posts the made it part but
nothing for the file. Now I created a ../uploads folder (which is in
the root, correct? I never could get the . or .. stuff right). But
it just will not work. Is it because I am running the server local?
Shouldn't be... Or is it something with the php.ini config or apache
config? Please help. This is really annoying...

Is your form set up correctly - enctype="multipart/form-data"

The name of the file won't be in $_POST, either. It will be in
$_FILES["FieldName"]["name"]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top