Upload file on php-5.2.2-3

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

kapil1089theking
Forum Commoner
Posts: 46
Joined: Wed May 28, 2008 1:51 pm
Location: Kolkata, India
Contact:

Upload file on php-5.2.2-3

Post by kapil1089theking »

Can anybody suggest the code to upload a file maximum size could be 2 gb.
dbemowsk
Forum Commoner
Posts: 82
Joined: Wed May 14, 2008 10:30 pm

Re: Upload file on php-5.2.2-3

Post by dbemowsk »

Just do a google search on PHP file uploads and you'll find quite a few tutorials on this.
kapil1089theking
Forum Commoner
Posts: 46
Joined: Wed May 28, 2008 1:51 pm
Location: Kolkata, India
Contact:

Re: Upload file on php-5.2.2-3

Post by kapil1089theking »

I m writing the script everything is shown fine that its written now what should I do I m not getting the file uploaded on the upload folder.
What reasons are probable can you plz help me?
kapil1089theking
Forum Commoner
Posts: 46
Joined: Wed May 28, 2008 1:51 pm
Location: Kolkata, India
Contact:

Re: Upload file on php-5.2.2-3

Post by kapil1089theking »

Create an Upload-File Form

Code: Select all

 
<html>
<body>
 
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>
 
</body>
</html>
Create The Upload Script

Code: Select all

<?php
if ($_FILES["file"]["type"] != "image/exe" )
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
 
    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>
 
Everything is fine only file is not visible in the upload folder, I guess it is not uploaded..
dbemowsk
Forum Commoner
Posts: 82
Joined: Wed May 14, 2008 10:30 pm

Re: Upload file on php-5.2.2-3

Post by dbemowsk »

I don't recall there being a mime type "image/exe". What type of image are you uploading?
kapil1089theking
Forum Commoner
Posts: 46
Joined: Wed May 28, 2008 1:51 pm
Location: Kolkata, India
Contact:

Re: Upload file on php-5.2.2-3

Post by kapil1089theking »

If Change the code to this then also not working.

Code: Select all

<?php
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
 
    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
?>
 
dbemowsk
Forum Commoner
Posts: 82
Joined: Wed May 14, 2008 10:30 pm

Re: Upload file on php-5.2.2-3

Post by dbemowsk »

To say it is not working does not help any of us help you. We need detailed information such as the errors you are getting. Help us help you.
dbemowsk
Forum Commoner
Posts: 82
Joined: Wed May 14, 2008 10:30 pm

Re: Upload file on php-5.2.2-3

Post by dbemowsk »

To say it is not working does not help any of us help you. We need detailed information such as the errors you are getting. Help us help you.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Upload file on php-5.2.2-3

Post by Benjamin »

Back up a minute here, I don't think your going to [reliably] be able to post 2gb files via a form. I would look into alternatives, such as creating a write only ftp folder.
kapil1089theking
Forum Commoner
Posts: 46
Joined: Wed May 28, 2008 1:51 pm
Location: Kolkata, India
Contact:

Re: Upload file on php-5.2.2-3

Post by kapil1089theking »

Plz help me to find out the errors i m not getting any error, I am using Linux with apache is the any need for granting with chmod, if so tell me what to do or tell me how to find out exactly the error.
kapil1089theking
Forum Commoner
Posts: 46
Joined: Wed May 28, 2008 1:51 pm
Location: Kolkata, India
Contact:

Re: Upload file on php-5.2.2-3

Post by kapil1089theking »

Ok if not possible for 2 gb then tell me how much is possible and do that only for me .
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Upload file on php-5.2.2-3

Post by Benjamin »

Can you say what is being uploaded?
kapil1089theking
Forum Commoner
Posts: 46
Joined: Wed May 28, 2008 1:51 pm
Location: Kolkata, India
Contact:

Re: Upload file on php-5.2.2-3

Post by kapil1089theking »

I want To Upload Any Kind of File
Here is what I am Getting With the Code.

Code: Select all

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
 
$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
 
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}
 
echo 'Here is some more debugging info:';
print_r($_FILES);
 
print "</pre>";
 
?>
 
Output as:

Possible file upload attack!
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => kaffeine.desktop
[type] => application/x-desktop
[tmp_name] => /tmp/phpv1V8cy
[error] => 0
[size] => 2921
)

)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Upload file on php-5.2.2-3

Post by Benjamin »

Well move_uploaded_file is returning false.

I'd check to make sure that your $uploaddir has write permissions enabled for the apache user.
kapil1089theking
Forum Commoner
Posts: 46
Joined: Wed May 28, 2008 1:51 pm
Location: Kolkata, India
Contact:

Re: Upload file on php-5.2.2-3

Post by kapil1089theking »

How Can I modify or see The Write permission for Apache User?
Post Reply