PHP Limit upload file size

Started on the old forum in October 2009 · view the original in the archive · old links redirect here

No replies · 733 views · started 17 years ago · 1 min read

riderz Lead · 975 posts #1

In this tutorial create 2 files

  1. limit_upload.php
  2. limit_upload_ac.php

Step

  1. Create file limit_upload.php
  2. Create file limit_upload_ac.php
  3. Create folder "upload" for store uploaded files.
  4. CHMOD your upload folder to "777" by using your ftp software(change permission).

Create file limit_upload.php

<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="limit_upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>File Upload (Limit file size 50 K)</strong></td>
</tr>
<tr>
<td align="center">Select file 
<input name="ufile" type="file" id="ufile" size="35" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

Create file limit_upload_ac.php

<?php
// Define file size limit 
$limit_size=50000;

//set where you want to store files
//in this example we keep file in folder upload 
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "upload/".$HTTP_POST_FILES['ufile']['name'];

if($ufile !=none)
{
// Store upload file size in $file_size 
$file_size=$HTTP_POST_FILES['ufile']['size'];

if($file_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";
}
else {
//copy file to where you want to store file
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>"; 
echo "<img src=\"$path\" width=\"150\" height=\"150\">";
}
else
{
echo "Copy Error";
}
}
}
?>

CHMOD upload folder to 777 (change permission)


Jacques jacques@gw-designs.co.za http://coding.biz.tm Come join and lets make it a place to learn all the noobies how to code


NEVER FORGET TO CLICK THE TANX BUTTON IF U LIKE WHAT IM SHARING OR HELPING WITH

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close