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

new to uploading files...

P: n/a
Well, I looked at an example from this group, tried it, and tried to
use it - but it does not work when I do it like this in PHP4.

<table>
<tr><td><input type="file" name="newfile" size="25"></td></tr>
<tr><td><input type="submit" name="sub_new" value="Upload"></td></
tr>
</table></form>

and in the same file, but ealier:

if($_POST["sub_new"]!="")
{
print "<pre>";
print_r($HTTP_POST_FILES);
echo "Uploading: ";
echo $HTTP_POST_FILES['newfile']['name'];
$file=strtolower($HTTP_POST_FILES['newfile']['name']);
$uploadfile = "../somwhere/".$file;
echo $uploadfile;
if (move_uploaded_file($HTTP_POST_FILES['newfile']['tmp_name'],
$uploadfile))
echo "<font color=\"blue\">$file uploaded.</font><p>";
}

I am never able to get the filename... why?

/S

Feb 14 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On Wed, 14 Feb 2007 12:54:50 -0800, jodleren wrote:
Well, I looked at an example from this group, tried it, and tried to use
it - but it does not work when I do it like this in PHP4.

<table>
<tr><td><input type="file" name="newfile" size="25"></td></tr>
<tr><td><input type="submit" name="sub_new" value="Upload"></td></
tr>
</table></form>
What's the opening form tag look like?

That is important...

Cheers,
Andy

--
Andy Jeffries MBCS CITP ZCE CMDEV
Zend Certified Engineer
Certified MySQL Developer
gPHPEdit Lead Developer - http://www.gphpedit.org

Feb 15 '07 #2

P: n/a
On Feb 15, 11:28 am, Andy Jeffries <n...@andyjeffries.co.ukwrote:
On Wed, 14 Feb 2007 12:54:50 -0800, jodleren wrote:
Well, I looked at an example from this group, tried it, and tried to use
it - but it does not work when I do it like this in PHP4.
<table>
<tr><td><input type="file" name="newfile" size="25"></td></tr>
<tr><td><input type="submit" name="sub_new" value="Upload"></td></
tr>
</table></form>

What's the opening form tag look like?
<form method=post name='myform' action='the_file_itself'>

BR
S
Feb 15 '07 #3

P: n/a
Rik
On Thu, 15 Feb 2007 13:28:32 +0100, jodleren <so*****@hot.eewrote:
On Feb 15, 11:28 am, Andy Jeffries <n...@andyjeffries.co.ukwrote:
>On Wed, 14 Feb 2007 12:54:50 -0800, jodleren wrote:
Well, I looked at an example from this group, tried it, and tried to
use
it - but it does not work when I do it like this in PHP4.
<table>
<tr><td><input type="file" name="newfile" size="25"></td></tr>
<tr><td><input type="submit" name="sub_new" value="Upload"></td></
tr>
</table></form>

What's the opening form tag look like?

<form method=post name='myform' action='the_file_itself'>
<form enctype="multipart/form-data" method="post" action="/">

Enctype is important.
--
Rik Wasmus
Feb 15 '07 #4

P: n/a
i had a similar problem in safari 2.0.3 resolved in 2.0.4
just close the tag files
<input type="file" name="newfile" size="25"/>

maybe like this
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input name="uploadedfile" type="file" />
<input type="submit" value="Upload File" />
</form>

jodleren wrote:
On Feb 15, 11:28 am, Andy Jeffries <n...@andyjeffries.co.ukwrote:
>On Wed, 14 Feb 2007 12:54:50 -0800, jodleren wrote:
>>Well, I looked at an example from this group, tried it, and tried to use
it - but it does not work when I do it like this in PHP4.
<table>
<tr><td><input type="file" name="newfile" size="25"></td></tr>
<tr><td><input type="submit" name="sub_new" value="Upload"></td></
tr>
</table></form>
What's the opening form tag look like?

<form method=post name='myform' action='the_file_itself'>

BR
S

Feb 15 '07 #5

P: n/a
On Feb 15, 2:52 pm, Rik <luiheidsgoe...@hotmail.comwrote:
On Thu, 15 Feb 2007 13:28:32 +0100, jodleren <sonn...@hot.eewrote:
On Feb 15, 11:28 am, Andy Jeffries <n...@andyjeffries.co.ukwrote:
On Wed, 14 Feb 2007 12:54:50 -0800, jodleren wrote:
Well, I looked at an example from this group, tried it, and tried to
use
it - but it does not work when I do it like this in PHP4.
<table>
<tr><td><input type="file" name="newfile" size="25"></td></tr>
<tr><td><input type="submit" name="sub_new" value="Upload"></td></
tr>
</table></form>
What's the opening form tag look like?
<form method=post name='myform' action='the_file_itself'>

<form enctype="multipart/form-data" method="post" action="/">

Enctype is important.
Thanks. I asume that it does not stop me from checking other actions
in my form?
I cannot test yet :-)

BR
Sonnich

Feb 15 '07 #6

P: n/a
On Feb 15, 2:51 pm, Daniele <"dmassaiu{["@]}yahoo.co.ukwrote:
i had a similar problem in safari 2.0.3 resolved in 2.0.4
just close the tag files
<input type="file" name="newfile" size="25"/>

maybe like this
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input name="uploadedfile" type="file" />
<input type="submit" value="Upload File" />
</form>
Will test.
Question: I see the MAX_FILE_SIZE, have seen it elsewhere.... any
special reason for that?

BR
Sonnich

Feb 15 '07 #7

P: n/a
Rik
On Thu, 15 Feb 2007 13:52:40 +0100, jodleren <so*****@hot.eewrote:
<form method=post name='myform' action='the_file_itself'>

<form enctype="multipart/form-data" method="post" action="/">

Enctype is important.

Thanks. I asume that it does not stop me from checking other actions
in my form?
I cannot test yet :-)
Any other normal postvalue is just handled fine indeed.
--
Rik Wasmus
Feb 15 '07 #8

P: n/a
jodleren wrote:
On Feb 15, 2:51 pm, Daniele <"dmassaiu{["@]}yahoo.co.ukwrote:
>i had a similar problem in safari 2.0.3 resolved in 2.0.4
just close the tag files
<input type="file" name="newfile" size="25"/>

maybe like this
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input name="uploadedfile" type="file" />
<input type="submit" value="Upload File" />
</form>

Will test.
Question: I see the MAX_FILE_SIZE, have seen it elsewhere.... any
special reason for that?

BR
Sonnich
from http://www.developershome.com/wap/wa....asp?page=php3

In the above HTML/XHTML code, the MAX_FILE_SIZE form field states that
the file to be uploaded should not be larger than 1048576 bytes. If a
browser supports this form field, it will not allow the user to choose a
file that is larger than 1048576 bytes. So, the user does not have to
wait for a file to upload to the server in order to find out whether it
is too large or not. However, at the time of writing, we cannot find any
WAP browsers that support the MAX_FILE_SIZE form field. Also, both IE 6
and Firefox 2.0 do not understand this form field.
Feb 15 '07 #9

P: n/a
Rik wrote:
On Thu, 15 Feb 2007 13:52:40 +0100, jodleren <so*****@hot.eewrote:
><form method=post name='myform' action='the_file_itself'>

<form enctype="multipart/form-data" method="post" action="/">

Enctype is important.

Thanks. I asume that it does not stop me from checking other actions
in my form?
I cannot test yet :-)

Any other normal postvalue is just handled fine indeed.
--Rik Wasmus
try this
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?
if (isSet($_POST['add'])) {
$uploaddir = '.';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);

echo '<pre>';
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
echo "file upload in " . $_FILES['file']['tmp_name'] ."\n";
}
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
echo "File was successfully uploaded.\n";
} else {
echo "File was NOT successfully uploaded.\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";
}
?>
<body>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="file" />
<input name="add" type="submit" id="add" value="add" />
</p>
</form>
</body>
</html>
Feb 15 '07 #10

P: n/a
Rik
On Thu, 15 Feb 2007 14:18:46 +0100, Daniele <"dmassaiu{["@]}yahoo.co.uk>
wrote:
Rik wrote:
>On Thu, 15 Feb 2007 13:52:40 +0100, jodleren <so*****@hot.eewrote:
>><form method=post name='myform' action='the_file_itself'>

<form enctype="multipart/form-data" method="post" action="/">

Enctype is important.

Thanks. I asume that it does not stop me from checking other actions
in my form?
I cannot test yet :-)
Any other normal postvalue is just handled fine indeed.
try this
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
New code, where is it transitioning from? New code should always be
strict...
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Untitled Document</title>
</head>
Open the body tag here, <preis illegal in the <head>
<?
if (isSet($_POST['add'])) {
$uploaddir = '.';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);

echo '<pre>';
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
echo "file upload in " . $_FILES['file']['tmp_name'] ."\n";
}
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
echo "File was successfully uploaded.\n";
} else {
echo "File was NOT successfully uploaded.\n";
}
What about:
switch($_FILES['file']['error']){
case UPLOAD_ERR_OK:
echo 'upload was fine';
if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)){
echo 'file was succesfully moved';
} else {
echo 'file could not be moved to '.$uploadfile;
}
break;
case UPLOAD_ERR_INI_SIZE:
echo 'file was bigger then allowed in php.ini';
break;
case UPLOAD_ERR_FORM_SIZE:
echo 'file was bigger then allowed in MAX_FILE_SIZE in the form';
break;
case UPLOAD_ERR_PARTIAL:
echo 'file was only partially uploaded';
break;
case UPLOAD_ERR_NO_FILE:
echo 'no file was uploaded';
break;
case UPLOAD_ERR_NO_TMP_DIR:
echo 'no temporary folder to write upload to';
break;
case UPLOAD_ERR_CANT_WRITE
echo 'problem writing file to disk';
break;
case UPLOAD_ERR_EXTENSION
echo 'file-upload stopped by extention';
break;
default:
echo 'Unknown error';
print_r($_FILES);
}

Seems a bit more informative.
--
Rik Wasmus
Feb 15 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.