Upload file problem

Links for php scripts

Moderators: macek, egami, gesf

kiwi
New php-forum User
New php-forum User
Posts: 124
Joined: Sun Feb 29, 2004 6:26 am
Contact:

Upload file problem

Postby kiwi » Sat Aug 28, 2004 6:48 am

i use this code to upload file, sometime can, some time can't, why

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '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>";

?>


when i can't upload , this error message show up,

Possible file upload attack! Here's some debugging info:
Array
(
[userfile] => Array
(
[name] => gap.mov
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)

)



any solution for this, help me, thanks

User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Postby gesf » Sat Aug 28, 2004 10:54 am

The code seems right!
In your $uploaddir, try to give the complete path to the upload directory!

Cheers

kiwi
New php-forum User
New php-forum User
Posts: 124
Joined: Sun Feb 29, 2004 6:26 am
Contact:

Postby kiwi » Sat Aug 28, 2004 10:57 am

but i try with the same coding, sometime it work, with the given file, it doesn't work, i don't think is the path problem, any other solution for this? thanks for helping

User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Postby gesf » Sun Aug 29, 2004 3:04 am

Really don´t know!
I´ve used this and it worked... try it:

Code: Select all

<?php

$uploaddir = "/complete_path/to/upload_dir/";

if(isset($_POST['submit'])) {

$file_realname = trim($_FILES['imagefile']['name']);
move_uploaded_file($_FILES['imagefile']['tmp_name'], $uploaddir . $file_realname) or die ('Error !');

echo 'File uploaded successfully !';

}

?>

darkforce2000
New php-forum User
New php-forum User
Posts: 13
Joined: Sat Jul 24, 2004 8:26 am

Postby darkforce2000 » Wed Oct 27, 2004 2:31 am

if i try to upload a file and the error code like below appear:

Warning: copy(/c:/Program Files/Apache Group/Apache2/htdocs/phpdoc/uploadchan_kah_yoong.jpg): failed to open stream: Invalid argument in C:\Program Files\Apache Group\Apache2\htdocs\phpdoc\act_update.php on line 35

wats wrong?
i set my upload directory as:

$upfiledir='/c:/Program Files/Apache Group/Apache2/htdocs/phpdoc/upload'.$pic_name;

if(copy($pic,$upfiledir))
{
echo("File Successfully copied!");
}
else
{
echo("Error in copying file");
}

can anyone help me?

Alex
New php-forum User
New php-forum User
Posts: 180
Joined: Fri Mar 07, 2003 4:59 pm
Contact:

Postby Alex » Wed Oct 27, 2004 5:44 am

try in

Code: Select all

move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)
to use double quotes, also you can try this function:

Code: Select all

function upload($filedir,$source,$source_name,$up_flag,$lastname)
{
   if (!file_exists($filedir))
   {
       mkdir($filedir,0777);
   }
   @chmod($filedir,0777);
   if (!$lastname)
   {
       $lastname=$source_name;
   }
   if (file_exists("$filedir/$lastname"))
   {
       if ($up_flag=="y")
       {
           @unlink($filedir/$lastname);
           @move_uploaded_file($source,"$filedir/$lastname");
           echo "$source_name OK<br>";
       }
       else
       echo "$source_name ...<br>";
   }
   else
   {
       @move_uploaded_file($source,"$filedir/$lastname");
       echo "$source_name OK<br>";
   }
}

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Wed Oct 27, 2004 7:21 am

You have a / before your c:/. That's bound to cause problems.

likik83
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Jan 09, 2005 1:15 am

More information?????

Postby likik83 » Sun Jan 09, 2005 1:22 am

Can u give me all of programming for upload file??? please URGENT

User avatar
Alexej Kubarev
Site Admin
Site Admin
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län
Contact:

Postby Alexej Kubarev » Sun Jan 09, 2005 2:31 am

All of that is found at php.net in comments for the upload function..

function upload($filedir,$source,$source_name,$up_flag,$lastname)
{
if (!file_exists($filedir))
{
mkdir($filedir,0777);
}
@chmod($filedir,0777);
if (!$lastname)
{
$lastname=$source_name;
}
if (file_exists("$filedir/$lastname"))
{
if ($up_flag=="y")
{
@unlink($filedir/$lastname);
@move_uploaded_file($source,"$filedir/$lastname");
echo "$source_name OK<br>";
}
else
echo "$source_name ...<br>";
}
else
{
@move_uploaded_file($source,"$filedir/$lastname");
echo "$source_name OK<br>";
}
}

All you need to do is post a data from a multipart form to the page that calles this function with $_FILES argument..


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest

cron