Link to home
Start Free TrialLog in
Avatar of altariamx2003
altariamx2003Flag for Mexico

asked on

How to upload big files with php

Hi

I have a form where I upload several images to my localhost server, the problem is when I try to upload images with more than 1 mb.

I check my php.ini and change it and I use this values now:
file_uploads = On
upload_max_filesize=10M
max_input_time = 1200
memory_limit = 128M
max_execution_time = 200
post_max_size=10M

The code that put in this post I use it with jquery multifile.

Everything works great when I try to upload tinny files, I dont know If I need to change another variable or something like that to allow uploads of bigger files.
<?php
foreach ($_FILES["files"]["error"] as $clave => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $nombre_tmp = $_FILES["files"]["tmp_name"][$clave];
        $nombre = $_FILES["files"]["name"][$clave];
        move_uploaded_file($nombre_tmp, $nombre);
    }
}
?>

Open in new window

Avatar of altariamx2003
altariamx2003
Flag of Mexico image

ASKER

Also if I use a single _FILE I can upload big files, I dont know what is happend

The problem is when I try to use an array of _FILE
$nombre_tmp = $_FILES["files"]["tmp_name"];
        $nombre = $_FILES["files"]["name"];
        move_uploaded_file($nombre_tmp, $nombre);

Open in new window

What method and encryption are you using in the form?
You allways need to set like in the snippet in order to send big data...
<FORM action="..." 
      enctype="multipart/form-data"
      method="post">

Open in new window

Also if you changed the values in your php.ini file you will need to restart your web server for those changes to take effect.
If the problem persists... Could you transcribe the error?
If you have no eror, try this at the beginin of the PHP code:
ini_set('display_errors', 1);
error_reporting(E_ALL ^E_WARNING ^E_NOTICE); // even without ^E_WARNING

Open in new window

run php info like below and look for upload_max_filesize.  This will ensure you have set your php.ini settings the way you want them.  (It is under the section CORE).

Then if it is wrong.  I know that WAMP installs have three or four php.ini files in different locations and the
       c:\wamp\bin\apache\apache2.xxx\bin\php.ini

is the one you need to change.

<?PHP
php_info();
?>
Here is my teaching sample that shows how to upload a file or three.  Please read it over - code, comments and especially the man page references (VERY important to read the manual about file uploads) and then post back here with any specific questions.

If this design pattern works for you, you're probably getting the problem from the jQuery side of things.

One other comment I might add,... the whole concept of HTTP file uploads was invented when a file of 800K was considered gigantic.  Today, you can hardly take a photo with a cell phone that is not a multiple of that size.  In other words, HTTP may not be the best technology for dealing with large file uploads.  You might want to consider using FTP instead.  I get away with using HTTP for most digital photos, but my clients are using cameras that generate 1 to 2 MB images.

HTH, ~Ray
<?php // RAY_upload_example.php
error_reporting(E_ALL);


// MANUAL REFERENCE PAGES
// http://docs.php.net/manual/en/features.file-upload.php
// http://docs.php.net/manual/en/features.file-upload.common-pitfalls.php
// http://docs.php.net/manual/en/function.move-uploaded-file.php
// http://docs.php.net/manual/en/function.getimagesize.php


// ESTABLISH THE NAME OF THE 'uploads' DIRECTORY
$uploads = 'uploads';

// ESTABLISH THE BIGGEST FILE SIZE WE CAN ACCEPT
$max_file_size = '8192000';  // EIGHT MEGABYTE LIMIT ON UPLOADS

// ESTABLISH THE MAXIMUM NUMBER OF FILES WE CAN UPLOAD
$nf = 3;

// ESTABLISH THE KINDS OF FILE EXTENSIONS WE CAN ACCEPT
$file_exts = array
( 'jpg'
, 'gif'
, 'png'
, 'txt'
, 'pdf'
)
;

// LIST OF THE ERRORS THAT MAY BE REPORTED IN $_FILES[]["error"] (THERE IS NO #5)
$errors = array
( 0 => "Success!"
, 1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini"
, 2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"
, 3 => "The uploaded file was only partially uploaded"
, 4 => "No file was uploaded"
, 6 => "Missing a temporary folder"
, 7 => "Cannot write file to disk"
)
;




// IF THERE IS NOTHING IN $_POST, PUT UP THE FORM FOR INPUT
if (empty($_POST))
{
    ?>
    <h2>Upload <?php echo $nf; ?> file(s)</h2>

    <!--
        SOME THINGS TO NOTE ABOUT THIS FORM...
        ENCTYPE IN THE HTML <FORM> STATEMENT
        MAX_FILE_SIZE MUST PRECEDE THE FILE INPUT FIELD
        INPUT NAME= IN TYPE=FILE DETERMINES THE NAME YOU FIND IN $_FILES ARRAY
    -->

    <form name="UploadForm" enctype="multipart/form-data" action="<?=$_SERVER["REQUEST_URI"]?>" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?=$max_file_size?>" />
    <p>
    Find the file(s) you want to upload and click the "Upload" button below.
    </p>

    <?php // CREATE INPUT STATEMENTS FOR UP TO $n FILE NAMES
    for ($n = 0; $n < $nf; $n++)
    {
        echo "<input name=\"userfile$n\" type=\"file\" size=\"80\" /><br/>\n";
    }
    ?>

    <br/>Check this box <input autocomplete="off" type="checkbox" name="overwrite" /> to <b>overwrite</b> existing files.
    <input type="submit" name="_submit" value="Upload" />
    </form>
    <?php
    die();
}
// END OF THE FORM SCRIPT



// WE HAVE GOT SOMETHING IN $_POST - RUN THE ACTION SCRIPT
else 
{
    // THERE IS POST DATA - PROCESS IT
    echo "<h2>Results: File Upload</h2>\n";

    // ACTIVATE THIS TO SEE WHAT IS COMING THROUGH
    //    echo "<pre>"; var_dump($_FILES); var_dump($_POST); echo "</pre>\n";

    // ITERATE OVER THE CONTENTS OF $_FILES
    foreach ($_FILES as $my_uploaded_file)
    {
        // SKIP OVER EMPTY SPOTS - NOTHING UPLOADED
        $error_code    = $my_uploaded_file["error"];
        if ($error_code == 4) continue;

        // SYNTHESIZE THE NEW FILE NAME
        $f_type    = trim(strtolower(end    (explode( '.', basename($my_uploaded_file['name'] )))));
        $f_name    = trim(strtolower(current(explode( '.', basename($my_uploaded_file['name'] )))));
        $my_new_file = getcwd() . '/' . $uploads . '/' . $f_name . '.' . $f_type;
        $my_file     =                  $uploads . '/' . $f_name . '.' . $f_type;

        // OPTIONAL TEST FOR ALLOWABLE EXTENSIONS
        if (!in_array($f_type, $file_exts)) die("Sorry, $f_type files not allowed");

        // IF THERE ARE ERRORS
        if ($error_code != 0)
        {
            $error_message = $errors[$error_code];
            die("Sorry, Upload Error Code: $error_code: $error_message");
        }

        // GET THE FILE SIZE
        $file_size = number_format($my_uploaded_file["size"]);

        // IF THE FILE IS NEW (DOES NOT EXIST)
        if (!file_exists($my_new_file))
        {
            // IF THE MOVE FUNCTION WORKED CORRECTLY
            if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
            {
                $upload_success = 1;
            }
            // IF THE MOVE FUNCTION FAILED
            else
            {
                $upload_success = -1;
            }
        }
        
        // IF THE FILE ALREADY EXISTS
        else
        {
            echo "<br/><b><i>$my_file</i></b> already exists.\n";

            // SHOULD WE OVERWRITE THE FILE? IF NOT
            if (empty($_POST["overwrite"]))
            {
                $upload_success = 0;
            }
            // IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
            else
            {
                $now    = date('Y-m-d');
                $my_bak = $my_new_file . '.' . $now . '.bak';
                if (!copy($my_new_file, $my_bak))
                {
                    echo "<br/><strong>Attempted Backup Failed!</strong>\n";
                }
                if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
                {
                    $upload_success = 2;
                }
                else
                {
                    $upload_success = -1;
                }
            }
        }

        // REPORT OUR SUCCESS OR FAILURE
        if ($upload_success == 2) { echo "<br/>It has been overwritten.\n"; }
        if ($upload_success == 1) { echo "<br/><strong>$my_file</strong> has been saved.\n"; }
        if ($upload_success == 0) { echo "<br/><strong>It was NOT overwritten.</strong>\n"; }
        if ($upload_success < 0)  { echo "<br/><strong>ERROR: $my_file NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND</strong>\n"; }
        if ($upload_success > 0)
        {
            echo "$file_size bytes uploaded.\n";
            if (!chmod ($my_new_file, 0755))
            {
                echo "<br/>chmod(0755) FAILED: fileperms() = ";
                echo substr(sprintf('%o', fileperms($my_new_file)), -4);
            }
            echo "<br/><a href=\"$my_file\">See the file $my_file</a>\n";
        }
    // END FOREACH ITERATOR - EACH ITERATION PROCESSES ONE FILE
    }
}

Open in new window

Hi

Im sorry for the delay, I was in the hospital

I think I found the problem with my files

I made this example to test whats happening and It works thats why I think the problem is in my form.

When I add the code to the form and I try  to upload big files the IE show that the files was uploaded fine but when I check my localhost the files was not there.

And again when I try with tinny files, everything works great and the files are in my localhost

Im gonna add both codes.

I know that Dreamweaver CS5 is not the best option, but Im really newbie In PHP hehehehe
// ******THIS IS THE EXAMPLE THAT I MADE TO TEST THE CODE******
// WHEN I TEST THIS CODE IN THIS EXAMPLE EVERYTHING WORK GREAT
// BUT THE SAME PHP CODE IN MY FORM CANT WORK AND THE BIG FILES CAN NOT BE UPLOADED
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<script src="../contenidos/jquery.js" type="text/javascript"></script>
<script src="../contenidos/jquery.MultiFile.js" type="text/javascript"></script>
</head>

<body>
<?php


function is_connected()
{ 
 $connected = @fsockopen('www.itssc.edu.mx', 80);
 if ($connected)
 { $is_conn = true; }
 else
 { $is_conn = false; }
 return $is_conn;
}

function fun_resizejpg($imgsrc,$imgnew)
{  
 if( file_exists($imgsrc) ) 
 {  
  list($srcx,$srcy,$ext) = getimagesize($imgsrc);
  $img = imagecreatefromjpeg($imgsrc);	 
  $new = imagecreatetruecolor (620, 465); 	 
  imagecopyresampled ($new, $img, 0, 0, 0, 0, 620,465,$srcx, $srcy);  	        
  imagejpeg($new,$imgnew,70); 
  imagedestroy($img);	   
  return true;
 } 
 else return false;
}

  
  
if(isset($_FILES['archivo']))
{		
 $cuenta=1;
 foreach ($_FILES['archivo']['error'] as $key => $error)
 {
  if (($error == UPLOAD_ERR_OK) && (is_connected() == true))
  {
   if(is_uploaded_file ($_FILES['archivo']['tmp_name'][$key]) && (is_connected() == true))
   {	
	$nom_galeria= "prueba-".$cuenta.".jpg";
	move_uploaded_file ($_FILES['archivo']['tmp_name'][$key], $_FILES['archivo']['name'][$key])  or die("Ocurrio un problema al intentar subir el archivo.");
    if ((fun_resizejpg($_FILES['archivo']['name'][$key],$nom_galeria) == true) && (is_connected() == true))
	{
	 
     $ok_image = true;
     $tmpfile = $_FILES['archivo']['tmp_name'][$key];
     $_FILES['archivo']['name'][$key] = $nom_galeria;
     $tmpname = $_FILES['archivo']['name'][$key];
     $ftpuser = "itssced";
     $ftppass = "|V!;M6##(1qp";
     $ftppath = "ftp.itssc.edu.mx/public_html/imagenes/";
     $ftpurl = "ftp://".$ftpuser.":".$ftppass."@".$ftppath;
     if ($tmpname != "") 
     {
      $fp = fopen($tmpname, 'r');
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $ftpurl.$tmpname);
      curl_setopt($ch, CURLOPT_UPLOAD, 1);
      curl_setopt($ch, CURLOPT_INFILE, $fp);
      curl_setopt($ch, CURLOPT_INFILESIZE, filesize($tmpname));
      curl_exec($ch);
      $error = curl_errno($ch);
      curl_close ($ch);
      if ($error == 0) 
      { 
       $rpta = 'Archivo subido correctamente.'; 
       $cuenta=$cuenta+1;
      } 
      else 
      { echo "<script type=\"text/javascript\">alert(\"Ocurrio un error, el registro no sera guardado. Intenta nuevamente\");</script>"; }
	 }
    }  
   }
   else echo "<script type=\"text/javascript\">alert(\"Ocurrio un error, el registro no sera guardado. Intenta nuevamente\");</script>"; 
  }
 }
}

?>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <table border="0" cellpadding="1" cellspacing="1" bgcolor="#0000FF">
    <tr>
      <td colspan="2" bgcolor="#FFFFFF"><input name="archivo[]"  class="multi" type="file" size="58" maxlength="10" accept="jpg" />
      <input name="nuevo" type="hidden" id="nuevo" />
        <label>
        <input type="submit" name="Submit" value="Enviar" />
      </label></td>
    </tr>
	<?php if(isset($ok_image)){ ?>
    <tr>
      <td width="144" align="center" bgcolor="#FFFFFF"><strong>original</strong></td>
      <td width="136" align="center" bgcolor="#FFFFFF"><strong>redimencionado</strong></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF"></td>
      <td bgcolor="#FFFFFF"></td>
    </tr>
	<?php } ?>
  </table>
</form>
</body>
</html>
// ************************************************************

// ************* AND THIS IS THE CODE OF MY FORM **************
<?php require_once('../Connections/dbnotes.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "registro_noticias")) {
	
// HERE IS HERE I WANT TO ADD THE PHP CODE OF MY EXAMPLE
// THIS CODE WORKS JUST WITH TINNY FILES
// WHEN I ADD THE PHP CODE OF MY EXAMPLE, THE FILES CANT BE UPLOADED	
	$directorio = '../imagenes/';
  if(isset($_FILES['archivo']))
  {
   $cuenta=1;
   $ide = $_POST['clave'];
   foreach ($_FILES['archivo']['error'] as $key => $error)
   {
    if ($error == UPLOAD_ERR_OK)
    {
     echo "$error_codes[$error]";
	 $nom_galeria= "gal".$ide."-".$cuenta.".jpg";
     move_uploaded_file($_FILES["archivo"]["tmp_name"][$key],$directorio.$nom_galeria) or die("Ocurrio un problema al intentar subir el archivo.");
	 $cuenta=$cuenta+1;
    }
   }
  }
  
// *************************************************************
  
if (is_uploaded_file($_FILES['fotos']['tmp_name']))
  {
   if($_FILES['fotos']['size'] < 8500000) 
   {
    if($_FILES['fotos']['type']=="image/bmp" ||$_FILES['fotos']['type']=="image/gif" || $_FILES['fotos']['type']=="image/jpeg" || $_FILES['fotos']['type']=="image/pjpeg") 
    {            
     $fotografia="../imagenes/".$_FILES['fotos']['name']; 
     copy($_FILES['fotos']['tmp_name'], $fotografia);
     $subio = true;
    }
   }
  }        
  if(!$subio) 
  { echo "El archivo no cumple con las reglas establecidas o no seleccionó una imagen"; }	 

  
  
  $insertSQL = sprintf("INSERT INTO noticias (clave, titulo, fecha, lugar, resumen, cuerpo, foto, galeria) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['clave'], "text"),
                       GetSQLValueString($_POST['titulo'], "text"),
                       GetSQLValueString($_POST['fecha'], "text"),
                       GetSQLValueString($_POST['lugar'], "text"),
                       GetSQLValueString($_POST['resumen'], "text"),
                       GetSQLValueString($_POST['cuerpo'], "text"),
                       GetSQLValueString($_POST['foto'], "text"),
                       GetSQLValueString($_POST['galeria'], "text"));

  mysql_select_db($database_dbnotes, $dbnotes);
  $Result1 = mysql_query($insertSQL, $dbnotes) or die(mysql_error());

  $insertGoTo = "index.html";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_dbnotes, $dbnotes);
$query_rs_dbnotes = "SELECT * FROM noticias";
$rs_dbnotes = mysql_query($query_rs_dbnotes, $dbnotes) or die(mysql_error());
$row_rs_dbnotes = mysql_fetch_assoc($rs_dbnotes);
$totalRows_rs_dbnotes = mysql_num_rows($rs_dbnotes);
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es">
<head>
<meta http-equiv="Content-Language" content="es">
<SCRIPT src="../contenidos/fsmenu.js" type=text/javascript></SCRIPT>

<SCRIPT language=JavaScript src="../contenidos/dbfunctions.js" 
type=text/JavaScript></SCRIPT>


<LINK id=listmenu-h href="../contenidos/listmenu_h.css" type=text/css rel=stylesheet>
<LINK id=estilos href="../contenidos/estilos.css" type=text/css rel=stylesheet>
<link href="../contenidos/calendar-blue.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Instituto Tecnologico SSC A.C.</title>
<script src="../contenidos/menu_principal.txt" type="text/javascript"></script>
<script src="../contenidos/jquery.js" type="text/javascript"></script>
<script src="../contenidos/jquery.MultiFile.js" type="text/javascript"></script>


		<script type="text/JavaScript" language="javascript" src="../contenidos/calendar.js"></script>
		<script type="text/JavaScript" language="javascript" src="../contenidos/lang/calendar-sp.js"></script>
		<script type="text/JavaScript" language="javascript" src="../contenidos/calendar-setup.js"></script>
<Style type="text/css">

           
            .resumen{font-family:Arial, Helvetica, sans-serif; font-size:20px;}
   
</STYLE>
<SCRIPT language=JavaScript>
<!--

var listMenu = new FSMenu('listMenu', true, 'display', 'block', 'none');
listMenu.showDelay = 0;
listMenu.switchDelay = 1;
listMenu.hideDelay = 0;
listMenu.cssLitClass = 'highlighted';
listMenu.animInSpeed = 1;
listMenu.animOutSpeed = 1;
listMenu.animations[listMenu.animations.length] = FSMenu.animFade;
listMenu.animations[listMenu.animations.length] = FSMenu.animSwipeDown;

var arrow = null;
if (document.createElement && document.documentElement)
{
 arrow = document.createElement('span');
 arrow.className = 'subind';
}
addEvent(window, 'load', new Function('listMenu.activateMenu("listMenuRoot", arrow)'));

//-->
</SCRIPT>
<SCRIPT language=JavaScript><!--
bandera = 0;
function mensajesv(variable, variable2)  
{ alert(variable); variable2.focus(); }




function regreso1(form)
{
 
  if(form.galerias[0].checked != false)
  { 
    form.elements['archivo[]'].disabled = false;
	
  }
  else
  { 
	if (contador_fotos >=1)
	{ var v = $('input:file');  v.MultiFile('reset'); }
    form.elements['archivo[]'].disabled = true; 
	form.elements['archivo[]'].value = "";
  }
}
function IsNumeric(valor)
{
 var log=valor.length; var sw="S";
 for (x=0; x<log; x++)
 { 
  v1=valor.substr(x,1);
  v2 = parseInt(v1);
  //Compruebo si es un valor numérico
  if (isNaN(v2)) 
  { sw= "N";}
 }
 if (sw=="S") 
 { return true; } 
 else 
 {return false; }
}

var primerslap=false;
var segundoslap=false;


function formateafecha(fecha)
{
 
 var long = fecha.length;
 var dia;
 var mes;
 var ano;
 
 if ((long>=2) && (primerslap==false)) 
 { 
  dia=fecha.substr(0,2);
  if ((IsNumeric(dia)==true) && (dia<=31) && (dia!="00")) 
  {
   fecha=fecha.substr(0,2)+"/"  +fecha.substr(3,7); 
   primerslap=true; 
  }
  else
  { fecha="";  primerslap=false;}
 }
 else
 { 
  dia=fecha.substr(0,1);
  if (IsNumeric(dia)==false)
  {fecha=""; }

  if ((long<=2) && (primerslap=true)) 
  { fecha=fecha.substr(0,1); primerslap=false; }
 }
 if ((long>=5) && (segundoslap==false))
 { 
  mes=fecha.substr(3,2); 
  if ((IsNumeric(mes)==true) &&(mes<=12) && (mes!="00")) 
  {  fecha=fecha.substr(0,5)+"/"+fecha.substr(6,4); segundoslap=true; }
  else 
  {  fecha=fecha.substr(0,3);; segundoslap=false;}
 }
 else
 { 
  if ((long<=5) && (segundoslap=true))
  { fecha=fecha.substr(0,4); segundoslap=false; }
 }
 if (long>=7)
 { 
  ano=fecha.substr(6,4);
  if (IsNumeric(ano)==false) 
  { fecha=fecha.substr(0,6); }
  else
  { 
   if (long==10)
   { 
    if ((ano==0) || (ano<1900) || (ano>2100)) 
    { fecha=fecha.substr(0,6); } 
   }
  }
 }
 if (long>=10)
 {
  fecha=fecha.substr(0,10);
  dia=fecha.substr(0,2);
  mes=fecha.substr(3,2);
  ano=fecha.substr(6,4);
  // Año no viciesto y es febrero y el dia es mayor a 28
  if ( (ano%4 != 0) && (mes ==02) && (dia > 28) ) 
  { fecha=fecha.substr(0,2)+"/"; }
 }
 return (fecha);
}

function valida (form)
{
	
 if (form.titulo.value == "") 
 { mensajesv("El contenido del campo TITULO no es valido", form.titulo); regreso1(form);  return(false); bandera = 1;}
 
 if (bandera == 0)
 {
  if (form.fecha.value == "") 
  { mensajesv("El contenido del campo FECHA no es valido", form.fecha); regreso1(form);  return(false); bandera = 1;}
 }
 
 if (bandera == 0)
 {
  if (form.lugar.value == "") 
  { mensajesv("El contenido del campo LUGAR no es valido", form.lugar); regreso1(form);  return(false); bandera = 1; }
 }
 
 
 if (bandera == 0)
 {
  var archivo="";
  archivo = document.getElementById('fotos').value;
  extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase();
  if (".jpg" != extension) 
  { 
   mensajesv("Comprueba la extensión del archivo a subir. \nSólo se pueden subir archivos con extensiones: jpg ",form.fotos);
   return(false);
   bandera = 1;
  }
  
 }
 
 
 
 if (bandera == 0)
 {
  if (form.resumen.value == "") 
  { mensajesv("El contenido del campo RESUMEN no es valido", form.resumen); regreso1(form);  return(false); bandera = 1;  }
 }
 
 if (bandera == 0)
 {
  if (form.cuerpo.value == "") 
  {  mensajesv("El contenido del campo CUERPO no es valido", form.cuerpo); regreso1(form);  return(false); bandera = 1;   }
 }
  
 if (bandera == 0)
 {  
  
  if(form.galerias[0].checked != false)
  {   
   if (form.elements['archivo[]'].value == "") 
   {   
    mensajesv("TE FALTA AÑADIR FOTOGRAFIAS PARA LA GALERIA", form.elements['archivo[]']); 
	regreso1(form); 
	form.elements['archivo[]'].disabled = false; 
	return(false); 
	bandera = 1; 
   }
   else
   { 
    form.galeria.value = 1;
   } 
  }
  if(form.galerias[1].checked != false)
  {   form.galeria.value = 0;  
  }
 }
 
 if (bandera == 0)
 {  
  if (contador_fotos >= 11)
  {   alert("SOLO PUEDES METER UN MAXIMO DE 10 FOTOS"); regreso1(form); return(false); bandera = 1;}
 }
 
 if (bandera == 0)
 {

  
   
   form.foto.value = form.fotos.value;
   total_registros(form);
 }
	 

	 
	 
	 
 if (bandera == 0)
 { 
 
 }
}

// --></SCRIPT>

<?php
echo '<script languaje="JavaScript"><!--

function total_registros(form)
{
 form.clave.value="'.$totalRows_rs_dbnotes.'";

 form.clave.value=parseInt(form.clave.value)+1;
}
 //-->
</script>';
?>

<style>
<!--
            .fondo{font-family:Arial; font-size:9pt;}			
            .txt {
	font-family: Verdana, Arial, sans-serif; 
	font-size: 10pt;
	line-height: 11pt;
	text-decoration: none;
	color: #000000;
	background-color: transparent;
}

.campo {
	font-family: Verdana, Arial, sans-serif; 
	font-size: 10pt;
	text-decoration: none;
	color: #000000;
	background-color: #eeeeee;
	border: 1px #aaaaaa solid;
	padding: 2px;
}
   
-->
</style>

</head>

<body marginwidth="0" marginheight="0" topmargin="0" leftmargin="0">
	<div align="center">
	<table border="0" width="950" cellspacing="0" cellpadding="0">
		<tr>
			<td width="950" colspan="2">
      <object
        classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
        codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,79,0"
        id="superior-final"
        width="950" height="129"
      >
        <param name="movie" value="../flash/superior-final.swf">
        <param name="bgcolor" value="#FFFFFF">
        <param name="quality" value="high">
        <param name="allowscriptaccess" value="samedomain">
        <embed
          type="application/x-shockwave-flash"
          pluginspage="http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"
          name="superior-final"
          width="950" height="129"
          src="../flash/superior-final.swf"
          bgcolor="#FFFFFF"
          quality="high"
          allowscriptaccess="samedomain"
        >
          <noembed>
          </noembed>
        </embed>
      </object>
    		</td>
		</tr>
		<tr>
			<td width="946" background="../imagenes/fondo-menu1.jpg">
	<table border="0" width="818" cellspacing="0" cellpadding="0">
		<tr>
			<td width="44">
      <object
        classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
        codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"
        id="inicio1"
        width="44" height="30"
      >
        <param name="movie" value="../flash/inicio1.swf">
        <param name="bgcolor" value="#FFFFFF">
        <param name="quality" value="high">
        <param name="allowscriptaccess" value="samedomain">
        <embed
          type="application/x-shockwave-flash"
          pluginspage="http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"
          name="inicio1"
          width="44" height="30"
          src="../flash/inicio1.swf"
          bgcolor="#FFFFFF"
          quality="high"
          allowscriptaccess="samedomain"
        >
          <noembed>
          </noembed>
        </embed>
      </object>
    		</td>
			<td width="774">
<script language="javascript" src="../contenidos/menu_principal.js"></script></td>
		</tr>
	</table>
			</td>
			<td width="4" background="../imagenes/tres_4.jpg">
	<img border="0" src="../imagenes/ctrans.gif" width="4" height="1"></td>
		</tr>
		<tr>
			<td width="950" colspan="2">
      		<img border="0" src="../imagenes/linea_abajo.jpg" width="950" height="3"></td>
		</tr>
	  </table>
	<div align="center">
	<table border="0" width="950" cellspacing="0" cellpadding="0">
		<tr>
			<td width="950">
			<img border="0" src="../cblanco.jpg" width="1" height="3"></td>
		</tr>
	  </table>
	<div align="center">
			<table border="0" width="950" cellspacing="0" cellpadding="0" id="table715">
				<tr>
					<td width="8">
					<img border="0" src="../imagenes/grissupizq.jpg" width="8" height="5"></td>
					<td width="934" background="../imagenes/otro_gris_mapa.jpg">
					<img border="0" src="../imagenes/ctrans.gif" width="1" height="1"></td>
					<td width="8">
					<img border="0" src="../imagenes/grissupder.jpg" width="8" height="5"></td>
				</tr>
				<tr>
					<td width="950" class="mapa_sitio" background="../imagenes/otro_gris_mapa.jpg" colspan="3" align="left">
					<font class="mapa">&nbsp;&nbsp; 
					<a href="../inicio.html">Inicio</a>&nbsp;&nbsp; 
					&gt;&nbsp;&nbsp; 
					<a href="index.html">Administración</a>&nbsp;&nbsp; 
					&gt;&nbsp;&nbsp; <a href="altas.html">Alta de noticias</a></font></td>
				</tr>
				<tr>
					<td width="8">
					<img border="0" src="../imagenes/grisinfizq.jpg" width="8" height="5"></td>
					<td width="934" background="../imagenes/otro_gris_mapa.jpg">
					<img border="0" src="../imagenes/ctrans.gif" width="1" height="1"></td>
					<td width="8">
					<img border="0" src="../imagenes/grisinfder.jpg" width="8" height="5"></td>
				</tr>
				<tr>
					<td width="950" colspan="3">
			<img border="0" src="../cblanco.jpg" width="1" height="3"></td>
				</tr>
			</table>
	  </div>
						


</div>
	</div>
													
	<div align="center">
		<table border="0" width="950" cellspacing="0" cellpadding="0">
			<tr>
				<td width="950" colspan="5" background="../imagenes/linea_superior.jpg">
									<img border="0" src="../imagenes/ctrans.gif" width="1" height="1"></td>
			</tr>
			<tr>
				<td width="1" background="../imagenes/cgris7.jpg">
									<img border="0" src="../imagenes/ctrans.gif" width="1" height="1"></td>
				<td width="754" valign="top" align="center">
							<table border="0" width="754" cellspacing="0" cellpadding="0">
								<tr>
									<td width="754" valign="top">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="3"></td>
								</tr>
								<tr>
									<td width="754" valign="top">
										<img border="0" src="../imagenes/noticias-alta.jpg" width="232" height="40"><table border="0" width="100%" cellspacing="0" cellpadding="0">
								<tr>
									<td align="center">
							<table border="0" width="754" cellspacing="0" cellpadding="0">
								<tr>
									<td width="754">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="6"></td>
								</tr>
								</table>
									</td>
								</tr>
							</table>
    
		 


										<div align="center">
										
										  <form name="registro_noticias" id="registro_noticias" enctype="multipart/form-data" method="POST" action="<?php echo $editFormAction; ?>" onSubmit="return valida (this)">
<center>
											<table border="0" width="753" cellspacing="0" cellpadding="0">
			<tr>
				<td width="753" align="right" valign="top" colspan="3">
					<img border="0" src="../imagenes/ctrans.gif" width="1" height="4"></td>
			</tr>
			<tr>
				<td width="94" align="right" valign="top"><font class="txt">Titulo&nbsp; *:</font></td>
				<td width="4">&nbsp;</td>
				<td width="655">
	<input type="text" class="campo" name="titulo" size="61"></td>
			</tr>
			<tr>
				<td width="753" align="right" valign="top" colspan="3">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="7"></td>
			</tr>
			<tr>
				<td width="94" align="right" valign="top"><font class="txt">Fecha&nbsp; *:</font></td>
				<td width="4">&nbsp;</td>
				<td width="655">
	 <input NAME="fecha" type="text" class="campo" id="fecha" size="10" maxlength="10"  onKeyUp = "this.value=formateafecha(this.value);"> <img src="../imagenes/calendario.png" name="Image1" id="Image1" width="16" height="16" border="0" id="Image1" onMouseOver="this.style.cursor='pointer'">
                                <script type="text/javascript">
                        					Calendar.setup(
                        					  {
                        					inputField : "fecha",
                        					ifFormat   : "%Y-%m-%d",
                        					button     : "Image1"
                        					  }
                        					);
                        		</script></td>
			</tr>
			<tr>
				<td width="753" align="right" valign="top" colspan="3">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="7"></td>
			</tr>
			<tr>
				<td width="94" align="right" valign="top"><font class="txt">Lugar&nbsp; *:</font></td>
				<td width="4">&nbsp;</td>
				<td width="655">
	<input type="text" class="campo" name="lugar" size="51"></td>
			</tr>
			<tr>
				<td width="753" align="right" valign="top" colspan="3">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="7"></td>
			</tr>
			<tr>
				<td width="94" align="right" valign="top"><font class="txt">Imagen&nbsp; *:</font></td>
				<td width="4">&nbsp;</td>
				<td width="655">
	<input type="file" class="campo" id="fotos" name="fotos" size="56"  />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	</td>
			</tr>
			<tr>
				<td width="753" align="right" valign="top" colspan="3">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="7"></td>
			</tr>
			<tr>
				<td width="94" valign="top" align="right"><font class="txt">Resumen&nbsp; *:</font></td>
				<td width="4">&nbsp;</td>
				<td width="655">
						<textarea rows="4" class="campo" name="resumen" cols="89"></textarea></td>
			</tr>
			<tr>
				<td width="753" align="right" valign="top" colspan="3">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="7"></td>
			</tr>
			<tr>
				<td width="94" align="right" valign="top"><font class="txt">Noticia&nbsp; *:</font></td>
				<td width="4">&nbsp;</td>
				<td width="655">
						<textarea rows="12" class="campo" name="cuerpo" cols="89"></textarea></td>
			</tr>
			<tr>
				<td width="753" align="right" valign="top" colspan="3">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="7"></td>
			</tr>
			<tr>
				<td width="753" valign="top" colspan="3"><font class="txt">&nbsp;¿ 
				Quieres añadir una galería de fotos para esta noticia ?:<input type="radio" value="V1" checked onClick="regreso1(form)" name="galerias">Sí&nbsp;&nbsp; 
				<input type="radio" name="galerias" onClick="regreso1(form)" value="V2">
				No
				</font></td>
			</tr>
			<tr>
				<td width="753" align="right" valign="top" colspan="3">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="7"></td>
			</tr>
			<tr>
				<td width="753" valign="top" colspan="3">
				<table border="0" width="753" cellspacing="0" cellpadding="0">
					<tr>
						<td width="197" align="right"><font class="txt">Seleccionar 
						archivo: *</font></td>
						<td width="4">&nbsp;</td>
						<td width="552">
						<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
	
      
	  <input name="archivo[]"  class="multi" type="file" size="58" maxlength="10" accept="jpg" /> <br />
	  </td>
					</tr>
				</table>
				</td>
			</tr>

			<tr>
				<td width="753" align="right" valign="top" colspan="3">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="10"></td>
			</tr>
			</table>
					</center>
  
        			
        <center><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></center>
     
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table603">
	<tr>
		<td width="100%">
		<p align="center"><font class="txt">LOS CAMPOS CON * SON OBLIGATORIOS</font></td>
	</tr>
	<tr>
		<td width="100%">
					<img border="0" src="../imagenes/ctrans.gif" width="1" height="4"></td>
	</tr>
	<tr>
		<td width="100%">
		<p align="center"><font class="txt">EL REGISTRO SERÁ AÑADIDO HASTA QUE 
		SALE EN PANTALLA EL MENSAJE:<br> <b>¡¡¡¡Registro añadido con éxito!!!!</b></font>
		  </td>
	</tr>
</table>

<input type="hidden" class="campo" id="clave" name="clave" value="d" size="26">
<input type="hidden" class="campo" id="galeria" name="galeria" value="d" size="26">
<input type="hidden" id="foto" name="foto" />
<input type="hidden" name="MM_insert" value="registro_noticias">
                                          </form>




										</div>
								  </td>
								</tr>
				  </table>
				</td>
				<td width="1" background="../imagenes/cgris7.jpg">
									<img border="0" src="../imagenes/ctrans.gif" width="1" height="1"></td>
				<td width="190" bgcolor="#F5F6F0" valign="top">
							<table border="0" width="100%" cellspacing="0" cellpadding="0">
								<tr>
							<td width="190" height="2" align="center" background="../imagenes/fondo_azul.jpg">
					
      						<b><font class="cuerpo_central" color="#FFFFFF">
							ADMINISTRACIÓN DE NOTICIAS</font></b></td>
								</tr>
								<tr>
							<td width="190" height="2" align="center">
					
							<img border="0" src="../imagenes/cgris2.jpg" width="190" height="2"></td>
								</tr>
								<tr>
							<td class="subindice1" width="190" height="2" align="center">
					
			<p align="left">
			<font class="menu_titulo">&nbsp; 
			<a href="../bachillerato.html">Alta de noticias</a><b><br>
			</b>&nbsp; 
			<a href="../aspirantes/bachillerato.html">Quitar noticias</a><b><br>
			</b>&nbsp; <a href="reinscripcion.html">Consultar noticias</a><b><br>
			</b>&nbsp; <font color="#BBBBBB"><a href="pestudios.html">Editar 
			noticias</a></font></font></td>
								</tr>
								<tr>
							<td width="190" height="2" align="center">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="2"></td>
							  </tr>
								<tr>
							<td width="190" height="2" align="center">
					
							<img border="0" src="../imagenes/cgris2.jpg" width="190" height="2"></td>
							  </tr>
								<tr>
							<td width="190" height="2" align="center">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="6"></td>
								</tr>
								<tr>
									<td width="100%" align="center">
									<table border="0" width="130" cellspacing="0" cellpadding="0" height="38">
										<tr>
											<td width="130" height="38" bgcolor="#EBF0FA">
									<a href="../biblio/index.html">
									<img border="0" src="../imagenes/biblioteca3.gif" width="150" height="46"></a></td>
										</tr>
									</table>
									</td>
								</tr>
								<tr>
									<td width="100%" align="center">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="5"></td>
								</tr>
								<tr>
									<td width="100%" align="center">
									<a href="../calendarios.html">
									<img border="0" src="../imagenes/calen1.jpg" width="150" height="46"></a></td>
								</tr>
								<tr>
									<td width="100%" align="center">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="5"></td>
								</tr>
								<tr>
									<td width="100%" align="center">
									<a HREF="#" target="_self" Onclick="abrir('http://www.itssc.edu.mx/radio.html', '249', '443',0,'radio_itssc')">
									<img border="0" src="../imagenes/radio-10.jpg" width="150" height="46"></a></td>
								</tr>
								<tr>
							<td width="190" height="2" align="center">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="6"></td>
								</tr>
								<tr>
							<td width="190" height="2" align="center">
					
							<img border="0" src="../imagenes/cgris2.jpg" width="190" height="2"></td>
								</tr>
								<tr>
							<td width="190" height="2" align="center">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="2"></td>
								</tr>
								<tr>
									<td width="100%" align="center">
									<table border="0" width="100%" cellspacing="0" cellpadding="0">
										<tr>
											<td class="subindice1" width="100%" align="right">

		<font class="menu_titulo">
							<font color="#000080">
		<a href="../contactanos.html">Solicita <b>más información</b></a></font></font></td>
										</tr>
										<tr>
							<td width="190" height="2" align="center">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="2"></td>
										</tr>
										<tr>
							<td width="190" height="2" align="center">
					
							<img border="0" src="../imagenes/cgris2.jpg" width="190" height="2"></td>
										</tr>
										<tr>
							<td width="190" height="2" align="center">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="2"></td>
										</tr>
										<tr>
											<td class="subindice1" width="100%" align="right">
      
		<font class="menu_titulo">
							<font color="#000080">
		<a href="../nosotros.html">Sobre el <b>ITSSC</b></a></font></font></td>
										</tr>
										<tr>
							<td width="190" height="2" align="center">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="2"></td>
										</tr>
										<tr>
							<td width="190" height="2" align="center">
					
							<img border="0" src="../imagenes/cgris2.jpg" width="190" height="2"></td>
										</tr>
										<tr>
							<td width="190" height="2" align="center">
					
			<img border="0" src="../imagenes/ctrans.gif" width="1" height="2"></td>
										</tr>
										<tr>
											<td width="100%" align="right">&nbsp;
      </td>
										</tr>
									  </table>
									</td>
								</tr>
				  </table>
							<p>&nbsp;</p>
				<p>&nbsp;</p>
				<p>&nbsp;</td>
				<td width="4" background="../imagenes/tres_4.jpg">
									<img border="0" src="../imagenes/ctrans.gif" width="1" height="1"></td>
			</tr>
			<tr>
				<td width="950" colspan="5">
			<img border="0" src="../imagenes/linea_abajo.jpg" width="950" height="3"></td>
			</tr>
		</table>
	</div><div align="center"><script language="javascript" src="../contenidos/inferior.js"></script></div>
					

</body>

</html>
<?php
mysql_free_result($rs_dbnotes);
?>
// ************************************************************

Open in new window

You posted almost a thousand lines of code.  Not sure where you might want us to look.

If you want to simplify the example, and just show us this information, we may be able to help.

1. Run phpinfo() and post the output here.
2. Show us the HTML form that selects the files for uploading - just the HTML.
3. Show us the code you have implemented for error handling (documented in these man pages)
http://docs.php.net/manual/en/features.file-upload.php
http://docs.php.net/manual/en/features.file-upload.common-pitfalls.php

My guess is that you are missing the MAX_FILE_SIZE form input field, or that your POST max file size is set very small.  We can see that sort of thing in the phpinfo() output.
1. link for the info of phpinfo(): http://www.itssc.edu.mx/phpinfo.html
2. link for the form code: http://www.itssc.edu.mx/form.txt
3. In this link you can find the php code: http://www.itssc.edu.mx/phpcode.txt
 
Let me try again what Im trying to do.

I had  a database in my remote server (itssc.edu.mx), I use the form to add new register, with any new register I need to add a new gallery for that image.

Because something the images that the user try to add could be larger I think that the form need to be in my localhost to upload and change their size and after that send them to itssc.edu.mx by ftp.

the form and the php code that I use works great with tinny images but when I try with bigger images nothing happend.

Im going to check the MAX_FILE_SIZE, maybe im missing something


Best regards
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your answer Ray

The reazon about why I had two INPUT TYPE=FILE statement in the same form is beacause this page is the news section of www.itssc.edu.mx, the first statement is for the main photo of the article, and the second statement is optional, and it is If the user want to add a gallery to the article, this second statement is an array and use it with "jquery.multifile" script.

I change the value of MAX_FILE_SIZE to 16192000, and also I change the values for uploads in all ini files related with php in the wamp server but the files cant be uploaded to localhost.

I think that something is missing maybe in my local server (wamp) because nomather what changes I made if I use the same code with big files nothing is uploated, but with  tinny files all images are uploaded to localhost.

Can you recommend another web server besides wamp????
I think I found the problem.

I add this line to my page: echo "<pre>"; var_dump($_FILES); var_dump($_POST); echo "</pre>\n";

And it show me the following information: http://www.itssc.edu.mx/var_dump.txt

I dont know where is that MAX_FILE_SIZE, because the statement that I use in my form has 16192000

Where i can found the other MAX_FILE_SIZE?????
I fix the problem with the MAX_FILE_SIZE and I can change It, but the problem remains

any idea????
Ray post a snippet with the following line (#11) in it:

<input type="hidden" name="MAX_FILE_SIZE" value="300000" /><!-- COULD THIS BE A PROBLEM?? -->

Did you made the change on this line?
hi ramelong

The problem wit that statement was that I need to write it in lowercase, but the problem remains
Why in lowercase? In this way it won't works...
May be we must try to by pass this constraint...
yes ramelong when i change <input type="hidden" name="MAX_FILE_SIZE" value="52428800" /> to <input type="hidden" name="max_file_size" value="52428800" /> the limit change

but no matter what the problem with the big files remains
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks ramelong

im gonna start from scratch, I think there is something wrong in my form and Im gonna check element by element to ensure that everything works fine

best regards for all
If you have any trouble, just post the problem ;)
One way to do what you need is to "echo" every "<input ...>" that you generete for the form... for instance, using htmlentities to avoit the HTML tags behavior of hidden itselves, since is too much easier to find in the browser screen (whit the find tool) than into te generated code.
echo '<input type=hiden name="fieldName" ... />';
echo htmlentities('<input type=hiden name="fieldName" ... />')';

Open in new window

I mean
echo htmlentities('<input type=hiden name="fieldName" ... />');

Open in new window