Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

- - - - -

Upload function not working

max_file_size

  • Please log in to reply
8 replies to this topic

#1 Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guest

Posted 06 February 2007 - 06:57 AM

I found this upload function on the internet and was trying to use it:


<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td>First name: <input name="fname" type="text"><br></td>
<td>Last name: <input name="lname" type="text"><br></td>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>

<?php

// Insert form values (fname, lname, userfile info)
$uploadDir = "C:\\xampp\\xampp\htdocs\upload\\";

if (isset($_POST['upload'])
&& !empty($_POST['fname'])
&& !empty($_POST['lname'])
&& !empty($_FILES['userfile']['name']))
{

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$filePath = $uploadDir . $fileName;

$result = move_uploaded_file($tmpName, $filePath) or die ('File upload failed: ' . mysql_error()) ;

if (!$result)
{
echo "Error uploading file";
exit;
}

include 'config.php';
include 'opendb.php';

if (!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}


$query = "INSERT INTO med_test (fname, lname, fileName, size, type, link, time)
VALUES ('$fname', '$lname', '$fileName', '$fileSize', '$fileType', '$filePath', NOW())";

mysql_query($query) or die ('insert query failed: ' . mysql_error());

include 'closedb.php';

echo "<br> Files uploaded<br>";

}
else { echo "Must fill in all fields "; }

?>


The problem is it only works for small files. I can't remember where I found it or I would go there for help. Any idea why large files do not work?
  • 0

#2 Guest_Jaan_*

Guest_Jaan_*
  • Guest

Posted 06 February 2007 - 10:18 AM

Well there's nothing wrong in here but... can you show me your config.php file?

but you have this part in your code:

<input type="hidden" name="MAX_FILE_SIZE" value="2000000"> 


this tells me that your max size is:

2000000 bytes
1953.125 kb
1.9073 mb


maybe there's something in your config.php file..
  • 0

#3 Chan

Chan

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 202 posts

Posted 10 February 2007 - 09:39 AM

I've learned that you need to change your php.ini file for the max size...
  • 0

#4 Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guest

Posted 10 February 2007 - 09:41 AM

So it is my HTML that is limiting the size or is it my php.ini?
  • 0

#5 Guest_Jaan_*

Guest_Jaan_*
  • Guest

Posted 10 February 2007 - 10:40 AM

well it can be php.ini to.. well check your php info like this:

<?php
echo phpinfo();
?>


and check this:

Posted Image

this shows how big files you can upload
  • 0

#6 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 10 February 2007 - 11:04 AM

So it is my HTML that is limiting the size or is it my php.ini?


potentially both
  • 0

#7 Guest_Jaan_*

Guest_Jaan_*
  • Guest

Posted 10 February 2007 - 04:29 PM

yup... well html can limit this uploading thingy only then if this code is executed...


<?php
$max_size = $_POST['MAX_FILE_SIZE'];
$fileSize = $_FILES['userfile']['size'];

if($fileSize>$max_size){
die("Your file is to big!");
}

?>


so i think there's problem in your php.ini ;)
  • 0

#8 Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guest

Posted 12 February 2007 - 04:00 PM

It was my php.ini file. I set the max upload to 40mb. Is that bad?
  • 0

#9 Guest_Jaan_*

Guest_Jaan_*
  • Guest

Posted 12 February 2007 - 10:15 PM

nope.. it's your own choice how big files you want to upload ;)
  • 0





Also tagged with one or more of these keywords: max_file_size

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download