473,324 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Help please with $_FILES

I have searched and have not gotten an understanding of $_FILES. I am
trying to do an upload to a directory "tmpdir" on the server. I have a
field defined as:

File name: <input name="filename" type="file" id="filename">

In my PHP code I have (with diagnostics):

echo "Will try to upload a file <br>";
echo "Tmp_Name: ".$_FILES['filename']['tmp_name']."<br>";
echo "Name: ".$_FILES['filename']['name']."<br>";
echo "Size: ".$_FILES['filename']['size']."<br>";
echo "Type: ".$_FILES['filename']['type']."<br>";
if ($_FILES['filename']['type'] == "mid/wav"){
echo "File of proper type <br>";
copy ($_FILES['filename']['tmp_name'],
"tmpdir/".$_FILES['filename']['name'])
or die ("Could not copy");
echo "";
echo "Name: ".$_FILES['filename']['name']."<br>";
echo "Size: ".$_FILES['filename']['size']."<br>";
echo "Type: ".$_FILES['filename']['type']."<br>";
echo "Copy Done....";
}

There are two problems.
1 - It doesn't enter to do the copy even though the file is a .mid file.
2 - The $_FILES['filename'] is empty.

I run the "browse" button and select that a file. Why is the $_FILES
superglobal empty?

If I comment out the "if" line and closing "}", the copy fails with a "Could
not copy", as expected since the filenames are empty.

Can someone please help me? (I have only been at this for a short while).

Shelly
Jul 17 '05 #1
6 2488
I noticed that Message-ID: <nL********************@comcast.com> from
Shelly contained the following:
File name: <input name="filename" type="file" id="filename">


Make sure you have this in a form including the following:
<form ENCTYPE="multipart/form-data" method="POST" action="">

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2

"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:d0********************************@4ax.com...
I noticed that Message-ID: <nL********************@comcast.com> from
Shelly contained the following:
File name: <input name="filename" type="file" id="filename">


Make sure you have this in a form including the following:
<form ENCTYPE="multipart/form-data" method="POST" action="">


It is enclosed in:

<form enctype="multipart/form-data" action="thisform.php" method="POST">

Shelly
Jul 17 '05 #3
Shelly <sh************@asap-consult.com> wrote:
[file uploading code]
There are two problems.
1 - It doesn't enter to do the copy even though the file is a .mid file.
2 - The $_FILES['filename'] is empty.

I run the "browse" button and select that a file. Why is the $_FILES
superglobal empty?

Can someone please help me? (I have only been at this for a short while).


A clear case of RTFM. Seeing your code I don't know where you got it
from, but it's definetly not from
http://www.php.net/manual/en/features.file-upload.php
which you should try first.

While your posted code is not complete I can only guess you didn't
supply the correct encoding type to the form necessary for uploading:
enctype="multipart/form-data"

Jul 17 '05 #4

"Daniel Tryba" <pa**********@invalid.tryba.nl> wrote in message
news:42***********************@news6.xs4all.nl...
Shelly <sh************@asap-consult.com> wrote:
[file uploading code]
There are two problems.
1 - It doesn't enter to do the copy even though the file is a .mid file.
2 - The $_FILES['filename'] is empty.

I run the "browse" button and select that a file. Why is the $_FILES
superglobal empty?

Can someone please help me? (I have only been at this for a short
while).
A clear case of RTFM. Seeing your code I don't know where you got it
from, but it's definetly not from
http://www.php.net/manual/en/features.file-upload.php
which you should try first.


I tried to find the FM using the search in www.php.net, but couldn't find
what you just pointed to. Thanks. I'll read that one.

While your posted code is not complete I can only guess you didn't
supply the correct encoding type to the form necessary for uploading:
enctype="multipart/form-data"


.....however, I **DID** supply the proper encoding.

Shelly
Jul 17 '05 #5

"Daniel Tryba" <pa**********@invalid.tryba.nl> wrote in message
news:42***********************@news6.xs4all.nl...
Shelly <sh************@asap-consult.com> wrote:
[file uploading code]
There are two problems.
1 - It doesn't enter to do the copy even though the file is a .mid file.
2 - The $_FILES['filename'] is empty.

I run the "browse" button and select that a file. Why is the $_FILES
superglobal empty?

Can someone please help me? (I have only been at this for a short
while).


A clear case of RTFM. Seeing your code I don't know where you got it
from, but it's definetly not from
http://www.php.net/manual/en/features.file-upload.php
which you should try first.

While your posted code is not complete I can only guess you didn't
supply the correct encoding type to the form necessary for uploading:
enctype="multipart/form-data"\


Here is the complete section and it still doesn't work:

<p>
<label></label>
<br>
<label> </label>
</p>
<form enctype="multipart/form-data" action="thisform.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
<p>File name: <input name="filename" type="file" id="filename">
</p>
<p>Description: <input name="description" type="text"
id="description">
<label> </label>
</p>
<p>
<label> </label>
<input name="submit" type="submit" value="Add Entry">
</p>
</form>
Jul 17 '05 #6
I have absolutely NO idea what happened, but it is working now. I really
didn't change anything. I went to the simple file where I got the method
and tried that one. It worked. So I compared with the one I wanted and
nothing was different. I moved a few echos, I and tried again and it
worked.

Thanks guys, the mystery continues but at least it is working now.

Oh, how do I specify multiple types. Right now I have "audio/mid", but I
would like to also allow .wav files.
Shelly
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
1
by: basestring | last post by:
Hi, I need help for my program. I'm new With PHP but i have programming skills in VB so it's quit easy to understand this language, however. i got my self in some problems that i don't understand....
0
by: foekall | last post by:
I used this script and test on my hosting. Evertimes appear "change permission to 777 failed. ". So, how to solve this error. Please kindly check for me and teach me. <?php $MAX_SIZE =...
3
by: Rabel | last post by:
I am having trouble with our server host they are saying that the php upload limit is 20 mbs but using the code below with my flash file I can only get it to do 8mbs. I know that asp is allowing...
3
by: skulkrinbait | last post by:
I've a HTML form that allows a user to specify the location to upload a file from: <p><label for = 'file'>Upload Graphics : <input type='file' name='imagefile' /></label></p> I then want to...
8
by: adamjblakey | last post by:
Hi, I am trying to build a function and from a script but it does not seem to be working. Can anyone see anything wrong with this? Also i need it to convert the large image to a specific size...
2
by: Joker7 | last post by:
Can anyone see why Im lossing the image type when it's renamed ! Thanks Chris <? session_start(); $n=$_FILES; $type=$_FILES; $size=$_FILES;
22
by: simon2x1 | last post by:
i have an image which width is 213 and height is 200 when i echo the image and i resize it echo "<img src='company/$present' width='70' height='68'/>"; the image was not as clear as when it was...
8
by: punk86 | last post by:
Hi, i been working on this codes but i keep getting broken links for the pictures. Im using apache. Need help for this please. I think its just the codes in my index.php is wrong and i do not know...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.