8791 sujets

Développement web côté serveur, CMS

Bonjour à tous!
Je viens poster sur ce forum, parce que j'ai grandement besoin de vos lumières.
Je suis débutant en PHP, et je suis embauché pour faire le site web d'un organisme au Québec
j'en suis arriver à la création de la partie administration (back office), tout fonctionne sauf mes upload.

Je vous mets en pièces jointes un exemple de bdd et mon fichier ou j'ai suivi un tuto pour le faire mais j'ai toujours une erreur de variable non définie que je n'arrive pas à illicider!

Cela fait une semaine que je cherche mais je dois pas etre assez compétent pour le résoudre seul!

Mon index.php
<?php
//	---------------------------------------------
//	Pure PHP Upload version 1.1
//	-------------------------------------------
if (phpversion() > "4.0.6") {
	$HTTP_POST_FILES = &$_FILES;
}
define("MAX_SIZE",0);
define("DESTINATION_FOLDER", "../upload");
define("no_error", "gestion_actu.php");
define("yes_error", "echec.php");
$_accepted_extensions_ = "";
if(strlen($_accepted_extensions_) > 0){
	$_accepted_extensions_ = @explode(",",$_accepted_extensions_);
} else {
	$_accepted_extensions_ = array();
}
$_file_ = $HTTP_POST_FILES['photo'];
if(is_uploaded_file($_file_['tmp_name']) && $HTTP_POST_FILES['photo']['error'] == 0){
	$errStr = "";
	$_name_ = $_file_['name'];
	$_type_ = $_file_['type'];
	$_tmp_name_ = $_file_['tmp_name'];
	$_size_ = $_file_['size'];
	if($_size_ > MAX_SIZE && MAX_SIZE > 0){
		$errStr = "File troppo pesante";
	}
	$_ext_ = explode(".", $_name_);
	$_ext_ = strtolower($_ext_[count($_ext_)-1]);
	if(!in_array($_ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0){
		$errStr = "Estensione non valida";
	}
	if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER)){
		$errStr = "Cartella di destinazione non valida";
	}
	if(empty($errStr)){
		if(@move_uploaded_file($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_)){
			header("Location: " . no_error);
		} else {
			header("Location: " . yes_error);
		}
	} else {
		header("Location: " . yes_error);
	}
}
?>
<?php require_once('Connections/obvrly.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"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO team (team_id, team_online, team_nom, team_prenom, team_mail, team_fonction, team_diplome, photo, team_etablissement) VALUES (%s, %s, %s, %s, %s, %s, %s, '$_name_', %s)",
                       GetSQLValueString($_POST['team_id'], "int"),
                       GetSQLValueString(isset($_POST['team_online']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['team_nom'], "text"),
                       GetSQLValueString($_POST['team_prenom'], "text"),
                       GetSQLValueString($_POST['team_mail'], "text"),
                       GetSQLValueString($_POST['team_fonction'], "text"),
                       GetSQLValueString($_POST['team_diplome'], "text"),
                       GetSQLValueString($_POST['team_etablissement'], "text"));

  mysql_select_db($database_obvrly, $obvrly);
  $Result1 = mysql_query($insertSQL, $obvrly) or die(mysql_error());

  $insertGoTo = "gestion_actu.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans titre</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Team_online:</td>
      <td><input type="checkbox" name="team_online" value="" checked="checked" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Team_nom:</td>
      <td><input type="text" name="team_nom" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Team_prenom:</td>
      <td><input type="text" name="team_prenom" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Team_mail:</td>
      <td><input type="text" name="team_mail" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Team_fonction:</td>
      <td><input type="text" name="team_fonction" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Team_diplome:</td>
      <td><input type="text" name="team_diplome" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Photo:</td>
      <td><input type="file" name="photo" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Team_etablissement:</td>
      <td><input type="text" name="team_etablissement" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Insérer un enregistrement" /></td>
    </tr>
  </table>
  <input type="hidden" name="team_id" value="" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>


Merci de prendre quelque minutes pour m'aider!
l'erreur Notice: Undefined index: photo in C:\wamp\www\upload\index.php on line 18
Désolé... j'ai pas vu que je l'avais pas mis un peu dans le rush!
Je te remets çà de suite !
<?php
//	---------------------------------------------
//	Pure PHP Upload version 1.1
//	-------------------------------------------
if (phpversion() > "4.0.6") {
	$HTTP_POST_FILES = &$_FILES;
}
define("MAX_SIZE",0);
define("DESTINATION_FOLDER", "../upload");
define("no_error", "gestion_actu.php");
define("yes_error", "echec.php");
$_accepted_extensions_ = "";
if(strlen($_accepted_extensions_) > 0){
	$_accepted_extensions_ = @explode(",",$_accepted_extensions_);
} else {
	$_accepted_extensions_ = array();
}
$_file_ = $HTTP_POST_FILES['photo'];
if(is_uploaded_file($_file_['tmp_name']) && $HTTP_POST_FILES['photo']['error'] == 0){
	$errStr = "";
	$_name_ = $_file_['name'];
	$_type_ = $_file_['type'];
	$_tmp_name_ = $_file_['tmp_name'];
	$_size_ = $_file_['size'];
	if($_size_ > MAX_SIZE && MAX_SIZE > 0){
		$errStr = "File troppo pesante";
	}
	$_ext_ = explode(".", $_name_);
	$_ext_ = strtolower($_ext_[count($_ext_)-1]);
	if(!in_array($_ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0){
		$errStr = "Estensione non valida";
	}
	if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER)){
		$errStr = "Cartella di destinazione non valida";
	}
	if(empty($errStr)){
		if(@move_uploaded_file($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_)){
			header("Location: " . no_error);
		} else {
			header("Location: " . yes_error);
		}
	} else {
		header("Location: " . yes_error);
	}
}
?>
<?php require_once('Connections/obvrly.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"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO team (team_id, team_online, team_nom, team_prenom, team_mail, team_fonction, team_diplome, photo, team_etablissement) VALUES (%s, %s, %s, %s, %s, %s, %s, '$_name_', %s)",
                       GetSQLValueString($_POST['team_id'], "int"),
                       GetSQLValueString(isset($_POST['team_online']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['team_nom'], "text"),
                       GetSQLValueString($_POST['team_prenom'], "text"),
                       GetSQLValueString($_POST['team_mail'], "text"),
                       GetSQLValueString($_POST['team_fonction'], "text"),
                       GetSQLValueString($_POST['team_diplome'], "text"),
                       GetSQLValueString($_POST['team_etablissement'], "text"));

  mysql_select_db($database_obvrly, $obvrly);
  $Result1 = mysql_query($insertSQL, $obvrly) or die(mysql_error());

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

C'est le code au dessus du DOC TYPE de index.php
Voilà!
<?php
//	---------------------------------------------
//	Pure PHP Upload version 1.1
//	-------------------------------------------
if (phpversion() > "4.0.6") {
	$HTTP_POST_FILES = &$_FILES;
}
define("MAX_SIZE",0);
define("DESTINATION_FOLDER", "../upload");
define("no_error", "gestion_actu.php");
define("yes_error", "echec.php");
$_accepted_extensions_ = "";
if(strlen($_accepted_extensions_) > 0){
	$_accepted_extensions_ = @explode(",",$_accepted_extensions_);
} else {
	$_accepted_extensions_ = array();
}
$_file_ = $HTTP_POST_FILES['photo'];
if(is_uploaded_file($_file_['tmp_name']) && $HTTP_POST_FILES['photo']['error'] == 0){
	$errStr = "";
	$_name_ = $_file_['name'];
	$_type_ = $_file_['type'];
	$_tmp_name_ = $_file_['tmp_name'];
	$_size_ = $_file_['size'];
	if($_size_ > MAX_SIZE && MAX_SIZE > 0){
		$errStr = "File troppo pesante";
	}
	$_ext_ = explode(".", $_name_);
	$_ext_ = strtolower($_ext_[count($_ext_)-1]);
	if(!in_array($_ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0){
		$errStr = "Estensione non valida";
	}
	if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER)){
		$errStr = "Cartella di destinazione non valida";
	}
	if(empty($errStr)){
		if(@move_uploaded_file($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_)){
			header("Location: " . no_error);
		} else {
			header("Location: " . yes_error);
		}
	} else {
		header("Location: " . yes_error);
	}
}
?>
<?php require_once('Connections/obvrly.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"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO team (team_id, team_online, team_nom, team_prenom, team_mail, team_fonction, team_diplome, photo, team_etablissement) VALUES (%s, %s, %s, %s, %s, %s, %s, '$_name_', %s)",
                       GetSQLValueString($_POST['team_id'], "int"),
                       GetSQLValueString(isset($_POST['team_online']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['team_nom'], "text"),
                       GetSQLValueString($_POST['team_prenom'], "text"),
                       GetSQLValueString($_POST['team_mail'], "text"),
                       GetSQLValueString($_POST['team_fonction'], "text"),
                       GetSQLValueString($_POST['team_diplome'], "text"),
                       GetSQLValueString($_POST['team_etablissement'], "text"));

  mysql_select_db($database_obvrly, $obvrly);
  $Result1 = mysql_query($insertSQL, $obvrly) or die(mysql_error());

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