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

PHP file upload problem

P: n/a
Hi all,

Heres a strange problem i am running into running Php4.2.2. I am
uploading a file using a post and when i receive the file on my share
the file adds some more records to it ( These are duplicate records
in the file). Dont know whats happening all input is appreciated.

Heres the code:
main.php
<?
....
echo "<FORM ENCTYPE='multipart/form-data' ACTION='abc.php'
METHOD=POST>";
echo "<INPUT TYPE=hidden name=MAX_FILE_SIZE value=1000000>";
echo "<INPUT NAME=userfile TYPE=file>";
echo "<INPUT TYPE=submit VALUE='Continue'>";
echo "</FORM>";
....
?>

abc.php

<?
....

$file = $HTTP_POST_FILES['userfile']['name'];

// this shows more than actual size;

echo $HTTP_POST_FILES['userfile']['size'];
if (is_uploaded_file($userfile)) {
copy($userfile, "/tmp/$file");

.... }

?>

Please advise.

Thanks
S
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
phantom wrote:
Heres a strange problem i am running into running Php4.2.2. I am
uploading a file using a post and when i receive the file on my share
the file adds some more records to it ( These are duplicate records
in the file). Dont know whats happening all input is appreciated.

Heres the code:
main.php
<?
...
echo "<FORM ENCTYPE='multipart/form-data' ACTION='abc.php'
METHOD=POST>";
echo "<INPUT TYPE=hidden name=MAX_FILE_SIZE value=1000000>";
echo "<INPUT NAME=userfile TYPE=file>";
echo "<INPUT TYPE=submit VALUE='Continue'>";
echo "</FORM>";
...
?>

abc.php

<?
...

$file = $HTTP_POST_FILES['userfile']['name'];

// this shows more than actual size;

echo $HTTP_POST_FILES['userfile']['size'];
if (is_uploaded_file($userfile)) {
copy($userfile, "/tmp/$file");

.... }

?>
Could you give us a sample of the files you're trying ( a before version and an
after version )?
You're sure that the new file is replacing the old one in /tmp (in other words,
you're sure that there's no error when the $userfile is being copied over
/tmp/$file)? If not, check the time.
Why did you code the last 2 lines like this:
if (is_uploaded_file($userfile)) {
copy($userfile, "/tmp/$file");


instead of using $HTTP_POST_FILES?

--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 16 '05 #2

P: n/a
>
Could you give us a sample of the files you're trying ( a before version and an
after version )?
You're sure that the new file is replacing the old one in /tmp (in other words,
you're sure that there's no error when the $userfile is being copied over
/tmp/$file)? If not, check the time.
Why did you code the last 2 lines like this:
if (is_uploaded_file($userfile)) {
copy($userfile, "/tmp/$file");


instead of using $HTTP_POST_FILES?

Before i mention about the files there is something strange i ran
into. On changing the files extension to abc.php3 from abc.php it
uploaded the files in the tmp directory correctly. The 3 extension is
for php version 3 i am guessing which was originally residing on the
server (we moved to php 4 lately a little bizarre) . Yeah so the point
is that the php3 extensions work fine whereas php itself does not. I
ran a php info() on the files labelled as php3 and as php but could
not find much differences. For one thing I am sure the problem lies
with the php-module its picking up... Shoould I be looking at
something else too. Please let me know

Now to answer about the files before and after.
Before its a simple txt file

James Douglas Buffalo NY
Rick Yale JacksonVille FL
.....

the records get messed up in no known format and so happens

as
James Douglas Buffalo NY
Rick Yale JacksonVille FL
.....

J Douglas Buffalo NY
Rick Yale JacksonVille FL

It is to note that the repetitive record drops some charactes as the
James turned J.

Thanks much
S
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.