File Uploading Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

File Uploading Problem

Post 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!!
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

Post by yosuke_ »

won't anybody help me? :cry:
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

Post by yosuke_ »

Thank you, you ware right!!! everything works now!! thank you!
Post Reply