Move_uploaded_file ,error 2

Username (e.g. epiz_XXX) or Website URL

epiz_33213468!, sucubus.

Error Message

La subida ha fallado archivos/d-emp-q23-(s).txt , 2

Other Information

i have this code in PHP, im trying to upload text files, and works perfectly with files less than 4000k, but i need to upload files greater than 500k and it causes an error, type 2.


///**********************

		echo "tmp name". $_FILES['subir_archivo']['tmp_name']."<br>";
		echo "tipo ".$_FILES['subir_archivo']['type']."<br>";
		echo "name ".$_FILES['subir_archivo']['name']."<br>";
		echo "tamaño ".$_FILES['subir_archivo']['size']."<br>";
		echo "<hr colorred>";
//****************************		
$fileError = $_FILES['subir_archivo']['error'];

echo "<div>";
if (move_uploaded_file($_FILES['subir_archivo']['tmp_name'], $subir_archivo)) {
      echo "El archivo es válido y se cargó correctamente.<br><br>";
	   //echo"<a href='".$subir_archivo."' target='_blank'><img src='".$subir_archivo."' width='150'></a>";
    } else {
       echo "La subida ha fallado $subir_archivo , $fileError ";
		echo $_FILES['subir_archivo']['tmp_name']."<br>";
		echo $_FILES['subir_archivo']['type']."<br>";
		echo $_FILES['subir_archivo']['name']."<br>";
		echo $_FILES['subir_archivo']['size']."<br>";
    }
    echo "</div>";

i have .htaccess file in htdocs like this

php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value max_execution_time 280
php_value max_input_time 280

doesnt work, i think.

how can i fix this issue??
thank you!

What are the sizes of the files you are trying to upload, in MB or KB?

Also, you can’t change php.ini settings using htaccess.

3 Likes

file to upload is 509kb (6000 lines of text) , and htaccess file has this lines:

php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value max_execution_time 280
php_value max_input_time 280

— formulario.html

<form enctype="multipart/form-data" action="upload.php" method="POST">

    <input type="hidden" name="MAX_FILE_SIZE" value="512000" />
   <p> Enviar mi archivo: <input name="subir_archivo" type="file" /></p>
   <p> <input type="submit" value="Enviar Archivo" /></p>
</form>

------ upload.php

<?php
//echo $_GET["subir_archivo"];
//echo "archivito = ".$archivito."<br>";
$directorio = "archivos/";
//$subir_archivo = $directorio.basename($_FILES['subir_archivo']['name']);
$minusculas=strtolower($_FILES['subir_archivo']['name']);
$subir_archivo = $directorio.basename($minusculas);
$longitud=strlen($minusculas);
$extension=substr($minusculas,$longitud-3,$longitud);


///**********************

		echo "tmp name". $_FILES['subir_archivo']['tmp_name']."<br>";
		echo "tipo ".$_FILES['subir_archivo']['type']."<br>";
		echo "name ".$_FILES['subir_archivo']['name']."<br>";
		echo "tamaño ".$_FILES['subir_archivo']['size']."<br>";
		echo "<hr colorred>";
//****************************		
$fileError = $_FILES['subir_archivo']['error'];

echo "<div>";
if (move_uploaded_file($_FILES['subir_archivo']['tmp_name'], $subir_archivo)) {
      echo "El archivo es válido y se cargó correctamente.<br><br>";
	   //echo"<a href='".$subir_archivo."' target='_blank'><img src='".$subir_archivo."' width='150'></a>";
    } else {
       echo "La subida ha fallado $subir_archivo , $fileError ";
		echo $_FILES['subir_archivo']['tmp_name']."<br>";
		echo $_FILES['subir_archivo']['type']."<br>";
		echo $_FILES['subir_archivo']['name']."<br>";
		echo $_FILES['subir_archivo']['size']."<br>";
    }
    echo "</div>";
?>

this formulario.html and upload.php works fine with a file with 300 lines ( 132k)

the files i want to upload are 509Kb, (6000 lines of text).
this program works fine with files 132Kb, (300 lines of text)

I think you are limited by this

Max execution time is around 25s.

If you want to upload files, use filezilla

2 Likes

I checked your code and I don’t see anything that’s clearly wrong with it.

Can you please share a bit more information as to what kind of issue you’re experiencing? What happens when you try to upload the file? What do all the different debug echo statements you added show?

4 Likes

I’m uploading a 1132kb file with 7000 lines to check. and thats the error I have.
if I upload a smaller file with 500 lines, works fine.

the max lines this program verify is 3000 lines. I was deleting lines to get this number

this program verify the sintaxis of the uploaded file.

I have changed this:

php_value max_execution_time 280
php_value max_input_time 280

to this

php_value max_execution_time 3600
php_value max_input_time 3600

and still have the error 2.

Max file size for HTML/PHP files is 1 MB

And you can’t change PHP settings in htaccess on free hosting.

If you need larger limits, check out premium hosting.

5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.