- upload.class.php
-
- class upload
- {
- private $img;
- private $dir;
-
- function __construct($img,$dir)
- {
- $this->tmp_img = $_FILES[$img]['tmp_name'];
- $this->nom_img = $_FILES[$img]['name'];
- $this->type_img =$_FILES[$img]['type'];
- $this->dossier=$dir;
- }
-
- function upload_image()
- {
- if( !is_uploaded_file($this->tmp_img) )
- {
- $msg="vous avez rien uploader";
- return $msg;
- }
- elseif( !strstr($this->type_img, 'jpg') && !strstr($this->type_img, 'jpeg') && !strstr($this->type_img, 'bmp') && ! strstr($this->type_img, 'gif') )
- {
- $msg="le fichier n'est pas une image";
- return $msg;
- }
- elseif( !move_uploaded_file($this->tmp_img, $this->dossier . $this->nom_img) )
- {
- $msg="impssible de copier le fichier";
- return $msg;
- }
-
- $msg="image envoyé";
- return $msg;
- }
- }//class
-
- upload.php
-
- session_start();
- include "upload.class.php";
- if(isset($_FILES['img']))
- {
-
- $img='img';
- $dir='./dir/';
- $koko = new upload($img,$dir);
- $er= $koko->upload_image();
-
- $_SESSION['er']=$er;
- header("location: upload-img.php");
- }
upload.class.php
class upload
{
private $img;
private $dir;
function __construct($img,$dir)
{
$this->tmp_img = $_FILES[$img]['tmp_name'];
$this->nom_img = $_FILES[$img]['name'];
$this->type_img =$_FILES[$img]['type'];
$this->dossier=$dir;
}
function upload_image()
{
if( !is_uploaded_file($this->tmp_img) )
{
$msg="vous avez rien uploader";
return $msg;
}
elseif( !strstr($this->type_img, 'jpg') && !strstr($this->type_img, 'jpeg') && !strstr($this->type_img, 'bmp') && ! strstr($this->type_img, 'gif') )
{
$msg="le fichier n'est pas une image";
return $msg;
}
elseif( !move_uploaded_file($this->tmp_img, $this->dossier . $this->nom_img) )
{
$msg="impssible de copier le fichier";
return $msg;
}
$msg="image envoyé";
return $msg;
}
}//class
upload.php
session_start();
include "upload.class.php";
if(isset($_FILES['img']))
{
$img='img';
$dir='./dir/';
$koko = new upload($img,$dir);
$er= $koko->upload_image();
$_SESSION['er']=$er;
header("location: upload-img.php");
}