begueradj
Messages postés273Date d'inscriptiondimanche 4 octobre 2009StatutMembreDernière intervention24 juin 2014
-
13 mars 2011 à 16:34
begueradj
Messages postés273Date d'inscriptiondimanche 4 octobre 2009StatutMembreDernière intervention24 juin 2014
-
14 mars 2011 à 14:50
Azul,
Il y a quleque chose qui cloche dans mon cul: lorsque je "upload" un fichier pdf dans mon forumlaire je reçois le message indiquant que ce n'est pas un fichier à extension validée or pour moi j'ai bien autorisé ces fichiers PDF,
Ci-dessous mon script, veuillez m'indiquer l'erreur si vous pouvez, merci:
<?php
if(isset($_POST['addport'])){
/*if the submit button that is related to adding a port is validated
* then */
/* is the file correctly uploaded ?*/
if(isset($_FILES['photo'])&&($_FILES['photo']['error'])==0){
/* check if the file is not too voluminous */
if($_FILES['photo']['size']<=3000000000){
/* extract basic file information */
$file_info=pathinfo($_FILES['photo']['name']);
/* check the extension of the file */
$file_extension=$file_info['extension'];
/*the allowed extensions*/
$allowed_extensions=array('jpg','png','jpeg','gif');
/* check if the file extension is allowed or not */
if(in_array($file_extension,$allowed_extensions)){
$file_name=time().'.'.$file_extension;
copy($_FILES['photo']['tmp_name'],'uploads/'.$file_name);
/*the file has been correctly uploaded */
echo'The file has been correctly uploaded';
if(!empty($_POST['name']) && !empty($_POST['unlocator']) && !empty($_POST['idnumber']) && !empty($_POST['position']) && !empty($_POST['berths']) && !empty($_POST['draft'])){
/* if all the fields are not empty then */
/*First , I retrieve all the data */
$name=$_POST['name'];
$unlocator=$_POST['unlocator'];
$idnumber=$_POST['idnumber'];
$position=$_POST['position'];
$berths=$_POST['berths'];
$draft=$_POST['draft'];
include('../Cfg/config.inc.php');
$link=mysql_connect($SERVER,$USER,$PWD) or die('Can not connect to the MySQL Server
'.mysql_error());
mysql_select_db($DB) or die('Can not connect to the requested database
'.mysql_error());
/* i need to inject the data to the ports table */
mysql_query("INSERT INTO ports (name,unlocator,idnumber,position,berths,draft,photo)VALUES ('$name','$unlocator','$idnumber','$position','$berths','$draft','$file_name')")or die('Insertion problem
'.mysql_error());
echo'
Ports data is correctly inserted !
';
}else{
/* at least one of the fields is empty */
echo'At least one field is empty, please, try again
!';
}
}else{
echo'Your photo must have a JPG, JPEG, PNG or GF format !';
}
}/*file is not too voluminous */
}/* file correctly uploaded */
}/* submit button pressed */
007Julien
Messages postés276Date d'inscriptionmercredi 22 septembre 2010StatutMembreDernière intervention 8 janvier 20144 14 mars 2011 à 14:16
Il s'agit simplement de tester le programme après avoir inséré un echo pour voir quelle est l'extension du fichier reçue et testée après l'upload...
// Insertion pour voir
echo $extensiondufichier;
// avant le test
if(in_array($extensiondufichier,$extensions_autorisees)){
// ...
}
Si jamais cette insertion provoquait un message d'erreur contenant headers already sent il conviendrait de retarder cet envoi (voir alors ob_start() et ob_end_flush()).