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

new to uploading files...

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
10 1368
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dickiedyce | last post by:
Hi there. I've spent the weekend getting ever more frustrated, trying to get an upload file function working on a website. The site is hosted by a company called oneandone. They're using PHP...
5
by: Kevin Ollivier | last post by:
Hi all, I've come across a problem that has me stumped, and I thought I'd send a message to the gurus to see if this makes sense to anyone else. =) Basically, I'm trying to upload a series of...
5
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and...
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...
0
by: Raj | last post by:
Hello, I am planning to provide the Pause/Resume while uploading files. Our site is using both java applet and activex to do this. The list of selected files will be stored in an encrypted...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
2
by: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post by:
jodleren escribió: I haven't found the PHP manual page where such feature is documented but a few tests have shown that this behaviour changes depending on the charset parameter of the...
1
by: =?Utf-8?B?RGFu?= | last post by:
MS won't seem to let me reply to my old post, so I created a new one. The error occurs in all browsers. It's definitely a server issue, not client. The server is not proxied in any way. I tried...
3
by: muziburrehaman | last post by:
i am looking for code in php to upload the 1 gb files. any one can please help me by sending the code....
0
by: LoriFranklin | last post by:
I'm a bit of a newbie here. I've learned a lot from reading the posts you all have here. I need some help uploading files using an asp form. I am using some code that I found from Jacob at...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...

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.