4

I'm trying to upload a file on my server with PHP, But it fails :

move_uploaded_file() returns false.

My file is a text file of 230,000 chars (224 ko)

However, if I try to reduce the file to 4500 chars, It works well.

Is there a maximum of the number of character ?

<?php

$host="";
$user="";
$pass="";
//$db = mysql_connect($host,$user,$pass);
//mysql_select_db('paul_biaudet',$db);
$dossier = 'update-';

$fichier = basename($_FILES['avatar']['name']);

$taille_maxi = 100000;
$taille = filesize($_FILES['avatar']['tmp_name']);
$extensions = array('.txt','.doc');
$extension = strrchr($_FILES['avatar']['name'], '.'); 
//security
if(!in_array($extension, $extensions)) 
{
     $erreur = 'Vous devez uploader un fichier texte';
}
if($taille>$taille_maxi)
{
     $erreur = 'too big';
}
if($_FILES['avatar']['name']!='shapes.txt' && $_FILES['avatar']['name']!='routes.txt' ){
    $erreur='...';
}
if(!isset($erreur)) //no error :  upload
{

     $fichier = strtr($fichier, 
          'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 
          'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
     $fichier = preg_replace('/([^.a-z0-9]+)/i', '-', $fichier);
     if(move_uploaded_file($_FILES['avatar']['tmp_name'], $dossier . $fichier)) 
     {
     ...
    }
else 
 {
      echo 'fail';
 }

And .... it's a fail

Thomas54
  • 55
  • 1
  • 1
  • 5

1 Answers1

4

Check your html code for a MAX_FILE_SIZE e.g.

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

Check your upload-max-filesize and post-max-size See: http://www.php.net/manual/fr/ini.core.php#ini.upload-max-filesize

and

http://www.php.net/manual/fr/ini.core.php#ini.post-max-size

What is the result for:

<?php
echo ini_get('upload-max-filesize'),'<br />'
,ini_get('post-max-size'),'<br />';
?>

Edit

upload_max_filesize = 2M and post_max_size = 8M

Strange... Try to make an upload with:

ini_set('upload-max-filesize', '10M');
ini_set('post_max_size', '10M');
Community
  • 1
  • 1
ImmortalPC
  • 1,650
  • 1
  • 13
  • 17