probleme avec is_uploaded_file

Eléphant du PHP | 107 Messages

05 mai 2010, 10:42

Bonjour,

j'ai un petit souci quand j'essai d'uploader un fichier(mp3) en local sur wamp :
Configuration Serveur
Version de Apache:
2.2.8
Version de PHP:
5.2.6

le souci c'est par exemple j'ai fixé dans mon php.ini les valeurs suivant
upload_max_filesize = 7M
post_max_size = 7M
memory_limit = 1024M

et quand j'essai d'uploader un fichier de 10mo il y a une condition qui n'est jamais vérifié dans mon méthode et aussi le script ne fait rien
if($files['fichier']['size'] < $this->maxSize())
voici mon code
 public function doUpload($files,$repertoire) {
	    	
			if($files['fichier']['error']!=UPLOAD_ERR_NO_FILE)
			{
				$tmp_name=$files['fichier']['tmp_name'];
				if(is_uploaded_file($tmp_name))
				{
					$type_file = $files['fichier']['type'];
					$allowed_types = array("audio/mpeg","application/octet-stream");	
					if(in_array($type_file,$allowed_types))
					{
							if($files['fichier']['size'] < $this->maxSize())
							{
								$this->namefile = $files['fichier']['name'];
								if(file_exists($repertoire) and !file_exists($repertoire.$this->namefile)) 
								{
									if(move_uploaded_file($tmp_name, $repertoire.$this->namefile))
									{
											echo " <strong>".$this->getName(). "</strong> is uploaded";
									}else{
											throw new Exception ("impossible to copy file");
											return false;
									}
								}else{
									throw new Exception ("<strong>".$this->getName()."</strong>  already exist");
									return false;
								}	
									
							}else{
									throw new Exception ("file size too big");
									return false;
							}			
					}else{
							throw new Exception ("type not authorized");
							return false;
					}
				}else{
					throw new Exception ("no file to upload");
					return false;
				}
			}else{
				throw new Exception ("file is empty : browse a file");
				return false;
			}
			
		}
if(isset($_POST['playlist']) and $_POST['playlist']!=null) {
		$destination = 'audiofile/'.$_POST['playlist'].'/';
		try 
		{
					$objetPlaylist->doUpload($_FILES,$destination);
					
		} catch (Exception $e) {			
					echo $e->getMessage();
		}
	}
<form method="post" action="<?php echo basename(__FILE__); ?>" enctype="multipart/form-data" >
									<table width="200" style="border:1px solid #dadada;margin:5px;">
										<tr>
											 <td colspan = "3"> <strong> UPLOAD NEW SONG PANEL</strong></td>
										</tr>
										<tr>
											<td><label>fichier:</label></td>
											<td><input type="hidden" name="playlist" value="<?php if(isset($_SESSION['playlist'])) echo $_SESSION['playlist']; ?>" ></input></td>
											<td><input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $objetPlaylist->maxSize(); ?>" /></td>
											<td><input type="file" name="fichier" ></input></td>
											
											
										</tr>
										<tr>
											<td></td>
											<td>&nbsp;</td>
											<td><input type="submit" value="Envoyer" /></td>
										</tr>
									</table>
								</form>
si vous avez une idée merci pour votre aide

Eléphant du PHP | 107 Messages

06 mai 2010, 16:33

jai trouvé la solution :

jai trouvé la solution

la valeur des paramètres (upload_max_filesize ,post_max_size)dans php.ini doit être différente(supérieure) de celle dans MAX_FILE_SIZE du formulaire

ça a marché maintenant