Page 1 of 1

File Uploading Problem

Posted: Tue Apr 20, 2004 4:38 am
by yosuke_
Hi!
Well, I have a problem with file uploading! I have uploadfrm.htm and upload.php pages and here is the code for upload.php

Code: Select all

<?
$uploaddir = '/upload/';
mkdir($uploaddir);
$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>";
?>
But this code dosnt seem to work!! Because when I try to upload image I get this:
Possible file upload attack! Here's some debugging info:
Array
(
[userfile] => Array
(
[name] => tokyo04.jpg
[type] =>
[tmp_name] =>
[error] => 2
[size] => 0
)

)
When I try to upload text file I get this:
File is valid, and was successfully uploaded. Here's some more debugging info:
Array
(
[userfile] => Array
(
[name] => im.txt
[type] => text/plain
[tmp_name] => C:\PHP\uploadtemp\php11F.tmp
[error] => 0
[size] => 8365
)

)
But It dosnt upload!!! I checked that C:\PHP\uploadtemp and my Uploal folder, but theres no file! :cry: And why doesnt it show filesize,type,etc. about image file? It shows this information only about txt file!! And here is another script that works!! I dont understand how it works, but it works! I fount it with google

Code: Select all

<?php
if(isset($_POST['upload'])){ 

copy($_FILES['file']['tmp_name'], "upload/" . $_FILES['file']['name']); 
unlink($_FILES['file']['tmp_name']); 
echo "File Uploaded Successfully"; 

} 
else
{
echo "error";
}
?>
With this script I can upload even pictures!!! I dont understand what does it mean unlink as far as I understand: script copies file from remote PC to webserver right?? Thank You!!

Posted: Tue Apr 20, 2004 5:46 am
by yosuke_
won't anybody help me? :cry:

Posted: Tue Apr 20, 2004 6:00 am
by JayBird
the first error is becuase of this
Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

Posted: Tue Apr 20, 2004 6:02 am
by JayBird
as to why you cant find the uploaded file.

This...

Code: Select all

$uploaddir = '/upload/';
should be

Code: Select all

$uploaddir = 'absolute/path/to/your/webserver/upload/';
im guessing if you look in you C:\ drive, you will find a file called uploads becuase that it where you actually told the script to put it!

Mark

Posted: Tue Apr 20, 2004 9:28 am
by yosuke_
Thank you, you ware right!!! everything works now!! thank you!