473,387 Members | 1,812 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,387 software developers and data experts.

Newbee - PHP File UPload Question

Hello,

I am trying to setup a file upload using the example from the PHP manual.
However, I am getting an Undefined index on userfile in the 2 places where
it is referenced. Can someone please tell me what this error means and why
it is happening?

Thank you,

Vic

Code Folows:

<?php
$uploadDir = '/var/www/uploads/';

$uploadFile = $uploadDir . $_FILES['userfile']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadFile))
{
print "File is valid, and was successfully uploaded. ";
print "Here's some more debugging info:\n";
print_r($_FILES);
}
else
{
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}
print "</pre>";

?>
Aug 14 '05 #1
4 1452
What is the output of print_r($_FILES) ?

Post the code you use for the form, too...

Aug 14 '05 #2
Here is the form code:

<%@ LANGUAGE="VBSCRIPT" %>

<%
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Simple Upload Example</title>
<meta name="Microsoft Border" content="none, default">
</head>

<body>

<h2 align="center">File Upload</h2>
<p>&nbsp;</p>
<%
'---
'--- Note the special form definition tag: ENCTYPE="multipart/form-data"
'---
%>
<form action="uploader.php" enctype="MULTIPART/FORM-DATA" method="POST">
<table width="100%">
<tr>
<td align="RIGHT" valign="TOP">Enter Filename:</td>
<%
'---
'--- Note the use of the TYPE="FILE" specification
'---
%>
<td align="LEFT"><input type="FILE" name="FILE1" size="75"><br>
Browse to select the file you wish to upload and press the &quot;Upload
File&quot;
button.<p>&nbsp;</td>
</tr>
<tr>
<td align="RIGHT">&nbsp;</td>
<td align="LEFT"><input type="SUBMIT" name="SUB1" value="Upload
File"></td>
</tr>
</table>
</form>

</body>

</html>
"ZeldorBlat" <ze********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
What is the output of print_r($_FILES) ?

Post the code you use for the form, too...

Aug 14 '05 #3
The index into the $_FILES array is the name of the input element. In
your form code you have:

<input type="FILE" name="FILE1" size="75">

so you should change:

$uploadFile = $uploadDir . $_FILES['userfile']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadFile))

in your original code to:

$uploadFile = $uploadDir . $_FILES['FILE1']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['FILE1']['tmp_name'], $uploadFile))

Note the index into the $_FILES array.

Aug 14 '05 #4
ZeldorBlat,

Thanks! I changed the form code to userfile and it got a little further.
Now I get the following error: Can you help?
Warning: move_uploaded_file(/var/www/uploads/test.zip): failed to open
stream: No such file or directory in
D:\html\users\176666\showseccom\html\Support\Uploa ds\uploader.php on line 5

Warning: move_uploaded_file(): Unable to move
'd:\PHP\uploadtemp\php2225.tmp' to '/var/www/uploads/test.zip' in
D:\html\users\176666\showseccom\html\Support\Uploa ds\uploader.php on line 5

Possible file upload attack! Here's some debugging info:
Array
(
[userfile] => Array
(
[name] => test.zip
[type] => application/x-zip-compressed
[tmp_name] => d:\PHP\uploadtemp\php2225.tmp
[error] => 0
[size] => 476131
)

)
Aug 15 '05 #5

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

Similar topics

13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
6
by: tshad | last post by:
I have an upload file input as: <input id="MyFile" style="width:300px" type="File" runat="Server"> This works fine, but I find that if my page doesn't pass validation during postback, the page...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
1
by: joshbeall | last post by:
Hi All, If I drop a form onto my page that allows file uploads, I know well enough how to handle the file upload in the server side via PHP. However, I have a question: when my browser...
9
by: CGW | last post by:
I asked the question yesterday, but know better how to ask it, today: I'm trying to use the File.Copy method to copy a file from a client to server (.Net web app under IIS ). It looks to me that...
2
by: Jonny | last post by:
Hiya all Using: ASP.NET Version 1.1 I am learning ASP.NET & would like to know:- How do I add a Open Browser Dialog behind a server button & validate a chosen file as a new e-mail...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
2
by: will.smothers | last post by:
All, I have two Windows Server 2003 boxes running IIS 6.0 webservers that host our proxy pac file. These two servers are behind a network load- balancer and house our corporation's Proxy PAC file....
1
by: lPrentice | last post by:
Hello, After all this time, Linux file permissions still confuse me at times. I have a Python web-based application with an file (images) upload module. The application is running on two remote...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.