Very strange file upload behavior

This is a discussion on Very strange file upload behavior within the PHP Language forums, part of the PHP Programming Forums category; I tried to search for this issue on the group, but don't even know where to start, so here'...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-02-2003
Courtney L.
 
Posts: n/a
Default Very strange file upload behavior

I tried to search for this issue on the group, but don't even know
where to start, so here's my problem.

We have a very simple form which has a file upload box.
Upon submit the file should be uploaded (using the copy function, from
the server's temp directory to our final directory), the database
should be updated, and the user should be notified of success/failure.
In that order. When we test it at the office, and even from a dial-up
at home, everything is fine.

When my client tries to do it from his cable modem connection here is
what happens: He chooses the file on the form, clicks submit and the
page churns away for a long while. Then, it just goes back to the form
page. In the meantime, the file has been moved to the server's temp
directory, but does not get to our final directory. The database gets
updated (which should only happen after the copy function), but no
confirmation message is given.

Here is some truncated code:

function upload_file()
{
global $target_dir,$target_file;
$upload_temp = $_FILES['filename_new']['tmp_name'];
$upload_file = $_FILES['filename_new']['name'];
$target_dir = "../downloads";
$target_file = $target_dir . "/" . $upload_file;

if (!copy($upload_temp, $target_file))
{
echo "<h4>Failed to upload file...<h4><br>\n";
die();
}
else
{
echo "<h4>Uploaded File Successfully...<h4><br>\n";
return;
}
}
upload_file();
$sql = "INSERT INTO downloads
(name,filename,sort_order,description,category,reg istration) VALUES
('".$name."','".$filename."',".$sort_order
..",'".$desc."',".$category.",".$registration.") ";

$result = mysql_db_query($glb_db,$sql) or die(mysql_error());

print "<p>The download has been added";
Reply With Quote
  #2 (permalink)  
Old 10-02-2003
Matthias Esken
 
Posts: n/a
Default Re: Very strange file upload behavior

possum_225@yahoo.com (Courtney L.) schrieb:

> if (!copy($upload_temp, $target_file))


Use move_uploaded_file() instead.

Regards,
Matthias
Reply With Quote
  #3 (permalink)  
Old 10-03-2003
Courtney L.
 
Posts: n/a
Default Re: Very strange file upload behavior

I'll give it a try right away. But can you help me understand the
logic of why this is better?

Matthias Esken <muelleimer2003nospam@usenetverwaltung.org> wrote in message news:<blhtlo.25o.1@usenet.esken.de>...
> possum_225@yahoo.com (Courtney L.) schrieb:
>
> > if (!copy($upload_temp, $target_file))

>
> Use move_uploaded_file() instead.
>
> Regards,
> Matthias

Reply With Quote
  #4 (permalink)  
Old 10-03-2003
Matthias Esken
 
Posts: n/a
Default Re: Very strange file upload behavior

possum_225@yahoo.com (Courtney L.) schrieb:

> I'll give it a try right away. But can you help me understand the
> logic of why this is better?


Read the documentation at
http://de3.php.net/manual/en/functio...oaded-file.php.

Their english is much better than mine. :-)

Regards,
Matthias
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:23 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0