Page 1 of 2
Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 8:48 am
by kapil1089theking
Can anybody suggest the code to upload a file maximum size could be 2 gb.
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 9:31 am
by dbemowsk
Just do a google search on PHP file uploads and you'll find quite a few tutorials on this.
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 9:51 am
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?
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 9:58 am
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..
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 10:10 am
by dbemowsk
I don't recall there being a mime type "image/exe". What type of image are you uploading?
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 10:15 am
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"];
}
}
?>
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 10:22 am
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.
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 10:23 am
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.
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 10:25 am
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.
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 10:28 am
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.
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 10:35 am
by kapil1089theking
Ok if not possible for 2 gb then tell me how much is possible and do that only for me .
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 10:39 am
by Benjamin
Can you say what is being uploaded?
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 10:45 am
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
)
)
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 10:53 am
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.
Re: Upload file on php-5.2.2-3
Posted: Sat Jun 07, 2008 10:55 am
by kapil1089theking
How Can I modify or see The Write permission for Apache User?