PDA

View Full Version : file uploads not giving error when over 12mb in size.


Josh
11-03-2010, 03:36 PM
Hi, i've created an upload script with a max file size of 12mb, when a file is uploaded of 20mb, the script gives the Upload Complete message, BUT, it doesn't upload the file to the server, which is ok but the user thinks it's been uploaded but it hasn't.

however if a 10mb file is uploaded, it gives the upload complete message, and the file is uploaded to my server. so that works.

the problem is I want it to give an error message when the file is too big.

here is my php code for when the user clicks Upload:


<?php

// properties of the uploaded file
$name = $_FILES["myfile"]["name"];
$type = $_FILES["myfile"]["type"];
$size = $_FILES["myfile"]["size"];
$temp = $_FILES["myfile"]["tmp_name"];
$error = $_FILES["myfile"]["error"];

if ($error > 0)

die("Error uploading file! Code $error.");
else

{

if ($size > 12000000) // conditions for the file
{
echo ("File size too big!");
}
else
{
move_uploaded_file($temp,"uploads/".$name);
echo "Upload Complete!";
}

}
?>


This is my uploads page code from where the user can upload a file:

<h1>Upload Your Performance...</h1>
<form action='upload.php' method='POST' enctype='multipart/form-data'>
<input type='file' name='myfile'><p>
<input type='submit' value='Upload'>

</form>


Please help,

Thanks,

Josh.

Josh
11-03-2010, 08:22 PM
anybody got any ideas please?

Josh.

edbr
11-04-2010, 02:12 AM
try this

// Define file size limit
$limit_size=50000;

if($size >= $limit_size){
echo "Your file size is over limit<BR>";
echo "Your file size = ".$file_size;
echo " K";
echo "<BR>File size limit = 50000 k";
}
its polite to be patient sometimes when you asking for help

Josh
11-04-2010, 02:38 AM
Thanks for that, I've not tried it yet but I will do later,

I wasn't being impolite, I have very good manners, however I do agree I should wait until I get a reply. When your stuck with something though you want to try and find a solution straight away. I didn't want to sound rude by doing that. Apologies.

Thank you for the help.

Josh.

Josh
11-04-2010, 02:54 AM
hmm it doesn't seem to work. Just does the same as before.

very annoying,

I replaced this;

if ($size > 12000000) // conditions for the file
{
echo ("File size too big!");
}
else
{
move_uploaded_file($temp,"uploads/".$name);
echo "Upload Complete!";
}



with your code, is that right? i changed the values to what i wanted them to be.

thanks,

Josh.

edbr
11-04-2010, 05:14 AM
not offended just not had coffee yet, some posters get very pushy.

echo $size; to see what you are returning on upload

davidj
11-04-2010, 08:29 AM
Ok this works... Tested as well

<?php

// properties of the uploaded file
$name = $_FILES["myfile"]["name"];
$type = $_FILES["myfile"]["type"];
$size = $_FILES["myfile"]["size"];
$temp = $_FILES["myfile"]["tmp_name"];
$error = $_FILES["myfile"]["error"];


if($size > 1400){

echo ("File size too big!");

}else{

move_uploaded_file($temp,$name);

echo "Upload Complete!";

}

echo "<pre>";
print_r($_FILES); //debug use only
echo "</pre>";



?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form action="" method="post" enctype="multipart/form-data" name="uploader">

<input type="hidden" name="MAX_FILE_SIZE" value="100000" />

<input name="myfile" type="file" />
<input type="submit" name="uploader2" id="uploader" value="Submit" />

</form>

</body>
</html>

Josh
11-04-2010, 12:19 PM
thanks for that guys.

But it still not working with either of those codes.

here is everything I have in my uploadpage.php, this is where the user would upload from.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/onlinestage_main.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>The Online Stage - Entertainment At It's Best!</title>
<!-- InstanceEndEditable -->
<link href="CSS/mainbody.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>
<body bgcolor="#FFFFFF" background="images/dancing-">
<div id="wrapper">
<div id="header">
<p><a href="login.html">Sign In</a>/ <a href="register.php">Register/ </a><a href="logout.php">Logout</a></p>
<p>&nbsp;</p>
<p><a href="http://www.onlinestage.freeforums.org/" target="&quot;_blank&quot;"><img src="images/images/Forums.gif" width="1000" height="34" border="0" /></a></p>
</div>

<div id="nav"><a href="index.html"><img src="images/images/Home.png" width="124" height="60" border="0" /></a><a href="HowItWorks.html"><img src="images/images/How-It-Works.png" width="124" height="60" border="0" /></a><a href="includes/News.html"><img src="images/images/News.png" width="124" height="60" border="0" /></a><img src="images/images/Competitions.png" width="123" height="60" border="0" /><a href="categories.html"><img src="images/images/Categories.png" width="123" height="60" border="0" /></a><a href="FutureEvents.html"><img src="images/images/Future-Events.png" width="124" height="60" border="0" /></a><a href="PrizeFunds.html"><img src="images/images/Prize-Funds.png" width="124" height="60" border="0" /></a><img src="images/images/View-Entries.png" width="131" height="60" border="0" /></div>
<div id="left_column">
<table id="Table_01" width="210" height="250" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<img src="images/images/NEWTOPSIDEBAR_01.gif" width="210" height="11" alt=""></td>
</tr>
<tr>
<td>
<img src="images/images/NEWTOPSIDEBAR_02.gif" alt="" width="210" height="48" border="0"></td>
</tr>
<tr>
<td>
<img src="images/images/NEWTOPSIDEBAR_03.gif" width="210" height="39" alt=""></td>
</tr>
<tr>
<td><a href="Winners.html"><img src="images/images/NEWTOPSIDEBAR_04.gif" alt="" width="210" height="49" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/NEWTOPSIDEBAR_05.gif" width="210" height="31" alt=""></td>
</tr>
<tr>
<td>
<img src="images/images/NEWTOPSIDEBAR_06.gif" alt="" width="210" height="48" border="0"></td>
</tr>
<tr>
<td>
<img src="images/images/NEWTOPSIDEBAR_07.gif" width="210" height="24" alt=""></td>
</tr>
</table>
<table id="Table_01" width="210" height="600" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><img src="images/images/sidebar_01.gif" alt="" width="210" height="26" border="0"></td>
</tr>
<tr>
<td><img src="images/images/sidebar_02.gif" alt="" width="210" height="39" border="0"></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_03.gif" width="210" height="42" alt=""></td>
</tr>
<tr>
<td><a href="includes/singing.html"><img src="images/images/sidebar_04.gif" alt="" width="210" height="39" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_05.gif" width="210" height="54" alt=""></td>
</tr>
<tr>
<td><a href="includes/dancing.html"><img src="images/images/sidebar_06.gif" alt="" width="210" height="39" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_07.gif" width="210" height="52" alt=""></td>
</tr>
<tr>
<td><a href="includes/music.html"><img src="images/images/sidebar_08.gif" alt="" width="210" height="39" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_09.gif" width="210" height="52" alt=""></td>
</tr>
<tr>
<td><a href="includes/sport.html"><img src="images/images/sidebar_10.gif" alt="" width="210" height="39" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_11.gif" width="210" height="46" alt=""></td>
</tr>
<tr>
<td><a href="includes/comedy.html"><img src="images/images/sidebar_12.gif" alt="" width="210" height="39" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_13.gif" width="210" height="42" alt=""></td>
</tr>
<tr>
<td><a href="includes/other.html"><img src="images/images/sidebar_14.gif" alt="" width="210" height="39" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_15.gif" width="210" height="13" alt=""></td>
</tr>
</table>
</div>
<!-- InstanceBeginEditable name="maincontent" -->

<div id="right_column">
<p class="content">
<h1>Upload Your Performance...</h1>
<form action="upload.php" method="post" enctype="multipart/form-data" name="uploader">
<input type="hidden" name="MAX_FILE_SIZE" value="12000000" />

<input name="myfile" type="file" />
<input type="submit" name="uploader2" id="uploader" value="Submit" />
</form>


<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div><!-- InstanceEndEditable -->
<div id="footer"><img src="images/images/Online-Stage.png" width="226" height="50" border="0" /><img src="images/images/Links.png" width="194" height="50" border="0" /><a href="ContactForm.html"><img src="images/images/Contact-Us.png" width="155" height="50" border="0" /></a><img src="images/images/Terms-&amp;-Conditions.png" width="145" height="50" border="0" /><a href="tell_a_friend.php"><img src="images/images/Tell-a-Friend.png" width="144" height="50" border="0" /></a><img src="images/images/Suggest-to-Us.png" width="136" height="50" border="0" /></div>
</div>
</body>
<!-- InstanceEnd --></html>



and this is what is in my upload.php, the script that's used when the user clicks submit to upload the file.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/onlinestage_main.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>The Online Stage - Entertainment At It's Best!</title>
<!-- InstanceEndEditable -->
<link href="CSS/mainbody.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>
<body bgcolor="#FFFFFF" background="images/dancing-">
<div id="wrapper">
<div id="header">
<p><a href="login.html">Sign In</a>/ <a href="register.php">Register/ </a><a href="logout.php">Logout</a></p>
<p>&nbsp;</p>
<p><a href="http://www.onlinestage.freeforums.org/" target="&quot;_blank&quot;"><img src="images/images/Forums.gif" width="1000" height="34" border="0" /></a></p>
</div>

<div id="nav"><a href="index.html"><img src="images/images/Home.png" width="124" height="60" border="0" /></a><a href="HowItWorks.html"><img src="images/images/How-It-Works.png" width="124" height="60" border="0" /></a><a href="includes/News.html"><img src="images/images/News.png" width="124" height="60" border="0" /></a><img src="images/images/Competitions.png" width="123" height="60" border="0" /><a href="categories.html"><img src="images/images/Categories.png" width="123" height="60" border="0" /></a><a href="FutureEvents.html"><img src="images/images/Future-Events.png" width="124" height="60" border="0" /></a><a href="PrizeFunds.html"><img src="images/images/Prize-Funds.png" width="124" height="60" border="0" /></a><img src="images/images/View-Entries.png" width="131" height="60" border="0" /></div>
<div id="left_column">
<table id="Table_01" width="210" height="250" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<img src="images/images/NEWTOPSIDEBAR_01.gif" width="210" height="11" alt=""></td>
</tr>
<tr>
<td>
<img src="images/images/NEWTOPSIDEBAR_02.gif" alt="" width="210" height="48" border="0"></td>
</tr>
<tr>
<td>
<img src="images/images/NEWTOPSIDEBAR_03.gif" width="210" height="39" alt=""></td>
</tr>
<tr>
<td><a href="Winners.html"><img src="images/images/NEWTOPSIDEBAR_04.gif" alt="" width="210" height="49" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/NEWTOPSIDEBAR_05.gif" width="210" height="31" alt=""></td>
</tr>
<tr>
<td>
<img src="images/images/NEWTOPSIDEBAR_06.gif" alt="" width="210" height="48" border="0"></td>
</tr>
<tr>
<td>
<img src="images/images/NEWTOPSIDEBAR_07.gif" width="210" height="24" alt=""></td>
</tr>
</table>
<table id="Table_01" width="210" height="600" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><img src="images/images/sidebar_01.gif" alt="" width="210" height="26" border="0"></td>
</tr>
<tr>
<td><img src="images/images/sidebar_02.gif" alt="" width="210" height="39" border="0"></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_03.gif" width="210" height="42" alt=""></td>
</tr>
<tr>
<td><a href="includes/singing.html"><img src="images/images/sidebar_04.gif" alt="" width="210" height="39" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_05.gif" width="210" height="54" alt=""></td>
</tr>
<tr>
<td><a href="includes/dancing.html"><img src="images/images/sidebar_06.gif" alt="" width="210" height="39" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_07.gif" width="210" height="52" alt=""></td>
</tr>
<tr>
<td><a href="includes/music.html"><img src="images/images/sidebar_08.gif" alt="" width="210" height="39" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_09.gif" width="210" height="52" alt=""></td>
</tr>
<tr>
<td><a href="includes/sport.html"><img src="images/images/sidebar_10.gif" alt="" width="210" height="39" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_11.gif" width="210" height="46" alt=""></td>
</tr>
<tr>
<td><a href="includes/comedy.html"><img src="images/images/sidebar_12.gif" alt="" width="210" height="39" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_13.gif" width="210" height="42" alt=""></td>
</tr>
<tr>
<td><a href="includes/other.html"><img src="images/images/sidebar_14.gif" alt="" width="210" height="39" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/images/sidebar_15.gif" width="210" height="13" alt=""></td>
</tr>
</table>
</div>
<!-- InstanceBeginEditable name="maincontent" -->
<div id="right_column">
<p class="content">
<?php
// properties of the uploaded file
$name = $_FILES["myfile"]["name"];
$type = $_FILES["myfile"]["type"];
$size = $_FILES["myfile"]["size"];
$temp = $_FILES["myfile"]["tmp_name"];
$error = $_FILES["myfile"]["error"];


if($size > 12000000){

echo ("File size too big!");

}else{

move_uploaded_file($temp,$name);

echo "Upload Complete!";

}

echo "<pre>";
print_r($_FILES); //debug use only
echo "</pre>";

?>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
<!-- InstanceEndEditable -->
<div id="footer"><img src="images/images/Online-Stage.png" width="226" height="50" border="0" /><img src="images/images/Links.png" width="194" height="50" border="0" /><a href="ContactForm.html"><img src="images/images/Contact-Us.png" width="155" height="50" border="0" /></a><img src="images/images/Terms-&amp;-Conditions.png" width="145" height="50" border="0" /><a href="tell_a_friend.php"><img src="images/images/Tell-a-Friend.png" width="144" height="50" border="0" /></a><img src="images/images/Suggest-to-Us.png" width="136" height="50" border="0" /></div>
</div>
</body>
<!-- InstanceEnd --></html>


really annoying, must be doing something wrong.

you can see the uploadpage at www.onlinestage.co.uk/uploadpage.php (http://www.onlinestage.co.uk/uploadpage.php) and the script runs from www.onlinestage.co.uk/upload.php (http://www.onlinestage.co.uk/upload.php)

thanks for your help.

Josh.

davidj
11-04-2010, 12:38 PM
looking at your code i dont think you really know whats going on. You really should use CSS and not tables for layout.

Josh
11-04-2010, 12:48 PM
The main body is created from css, there just my pages from my template, argh all of this stuff is complicated.
I've buillt alot of the website now, www.onlinestage.co.uk (http://www.onlinestage.co.uk) I don't really want to have to change everything.

I know I'm only a beginner, but I didn't think I was doing that bad.

Is everything wrong?

davidj
11-04-2010, 12:58 PM
i know that what i posted works

you need to look at that and work from there

Josh
11-04-2010, 01:04 PM
ok thanks david. il have a look.

are you a web designer? i.e. can I pay you to sort out the mess I might have created in my website?

Josh
11-04-2010, 02:29 PM
Right I think I've found the problem, the code works, however it takes the length of time the file would take to be uploaded before it realises that the file is too big,

I want it to be instant if that can be done?


<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>


here's the html,

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="12000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

so it works, but not how I'd hoped.

I'm sorry if im becoming irritating, I don't mean to, Im keen to learn and I appreciate all the help i'm getting.

davidj
11-04-2010, 04:14 PM
php is processed on the server. The file needs to be uploaded before the script can evaluate the size of the file

its how it works.

Josh
11-04-2010, 04:38 PM
right ok, thanks for clearing that up for me.

thanks for your help.

davidj
11-04-2010, 04:54 PM
no problem