473,414 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

max file size

anfetienne
424 256MB
how can i incorporate a limit to file sizes into the codes below?

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2.  
  3.     function addField() {
  4.     var tbody = document.getElementById("tblBody");
  5.     var ctr = tbody.getElementsByTagName("input").length + 1;
  6.     var input;
  7.  
  8.     if ( ctr > 75 ) {
  9.           alert ("The maximum number of images has been reached.");
  10.     }else{
  11.  
  12.         if (document.all){ //input.name doesn't work in IE
  13.             input = document.createElement('<input name="images[]">');
  14.         }else{
  15.             input = document.createElement('input');
  16.             input.name = "images[]";
  17.         }
  18.  
  19.         input.id = input.name;
  20.         input.type = "file";
  21.         input.value = "";
  22.         input.className = "images[]";
  23.         var cell = document.createElement('td');
  24.         cell.style.height = '30px';
  25.         cell.appendChild(document.createTextNode(ctr+". "));
  26.         cell.appendChild(input);
  27.         var row = document.createElement('tr');
  28.         row.appendChild(cell);
  29.         tbody.appendChild(row);
  30.  
  31.         window.document.the_form.count.value = ctr;
  32.  
  33.     }
  34. </script>
  35.  
  36.  
  37.  
  38. <body>
  39.  
  40.  
  41.  
  42.  
  43.     <form name="the_form" id="the_form" method="POST" action="addimgck.php" enctype="multipart/form-data">
  44.  
  45.           <table width="100%"  border="0" cellspacing="0" cellpadding="0">
  46.           <tbody id="tblBody">
  47.             <tr>
  48.               <td height="30">
  49.                 1. <input name="images[]" type="file" class="imgfield" id="field_1" />
  50.               </td>
  51.             </tr>
  52.             <tr>
  53.               <td height="30">
  54.                 2. <input name="images[]" type="file" class="imgfield" id="field_2" />
  55.               </td>
  56.             </tr>
  57.             <tr>
  58.               <td height="30">
  59.                 3. <input name="images[]" type="file" class="imgfield" id="field_3" />
  60.               </td>
  61.             </tr>
  62.             <tr>
  63.               <td height="30">
  64.                 4. <input name="images[]" type="file" class="imgfield" id="field_4" />
  65.               </td>
  66.             </tr>
  67.             <tr>
  68.               <td height="30">
  69.                 5. <input name="images[]" type="file" class="imgfield" id="field_5" />
  70.               </td>
  71.             </tr>
  72.  
  73.         </table>
  74.           <input name="count" type="hidden" id="count" value="4"/>
  75.           <input type="hidden" name="returnURL" id="returnURL" value="<?php print $returnURL;?>" />      
  76.           <input type="hidden" name="ID" id="ID" value="<?php print $random_digit;?>" /> 
  77.           <input name="add" type="button" class="button" id="add" value="Add Image(s)" onClick="addField();"/>          
  78.           <input name="Submit" type="submit" value="Upload Image" />
  79.     </form>
  80.  

Expand|Select|Wrap|Line Numbers
  1. while(list($key,$value) = each($_FILES['images']['name']))
  2.         {
  3.             if(!empty($value))
  4.             {
  5.                 $filename = $value;
  6.                     $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
  7.  
  8.                     $add = "upload/imgtemp/m/$random_digit/$filename";
  9.                     $tempFLDR = "upload/imgtemp/t/$random_digit/$filename";
  10.                        //echo $_FILES['images']['type'][$key];
  11.                  // echo "<br>";
  12.                     copy($_FILES['images']['tmp_name'][$key], $add);
  13.                     chmod("$add",0777);
  14.                     copy($_FILES['images']['tmp_name'][$key], $tempFLDR);
  15.                     chmod("$tempFLDR",0777);
  16.  
Jun 8 '09 #1
1 1914
Atli
5,058 Expert 4TB
Try checking the file size and not saving it if it is to big.

The $_FILES array provides the exact size of the file in question.
A simple if statement could tell you if the file is to big.
Jun 8 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
4
by: M P | last post by:
Can you help me find an asp code that will upload a file from my PC to web server? Mark
11
by: Skc | last post by:
I have a .txt which has been exported as a .csv from an external source. What i need to do is to import this into SQL2000 (into a table) but I need to do special things on the data: 1. I need to...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
1
by: BW | last post by:
I am creating an upload/download function for an extranet site. Files will be uploaded to directory based upon the users login and associated project. The function works as long as I use "c:\Temp"...
2
by: Dan | last post by:
Hi, I know this code is not entirely javascript, but bare with me. Can you please tell me why this does not work: page: filemanager.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
1
by: j7.henry | last post by:
I am trying to pull specific data that is in a comma delimited file into a web page. So if my comma delimited file looks like: Name,Address,Zip Fred,123 Elm,66666 Mike,23 Jump,11111 I would...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
2
by: cleary1981 | last post by:
Hi, I have created a script in PHP thats generates an SVG image. Want I want to do is have PHP save this as example.svg. Can this be done? Heres my code <?php require "config.php"; $proj_id =...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.