1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
   | if (!empty($_FILES)) {
	$tempFile = $_FILES['Filedata']['tmp_name'];
	$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
 
	/*
	$auv = array('/','..');
	$aup = array('','');
	$toto = str_replace($auv, $aup, $_REQUEST['folder']);
 
	$fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
	if(($fileTypes=="jpg") || ($fileTypes=="jpeg")){	
 
	*/
	if($_FILES['Filedata']['type']='image/jpeg'){
 
 
	//*************************
	// Création de vignettes 
	//*************************
 
	// Définir les paramètres
	$oldname = $_FILES['Filedata']['tmp_name'];
	$normal = $id.".jpg";
	$vignette = $id."_tn.jpg";
	$newh = 256;
 
 
	$targetNormal =  str_replace('//','/',$targetPath) . $normal;
	$targetVignette =  str_replace('//','/',$targetPath) . $vignette;
 
	// Interpoler les dimensions
	$size = getImageSize($oldname);
	$w = $size[0];
	$h = $size[1];
	$neww = intval($newh * $w / $h);
 
	// Recréer une image de taille inférieure
	$resimage = imagecreatefromjpeg($oldname); 
	$newimage = imagecreatetruecolor($neww, $newh);  
	imageCopyResampled($newimage, $resimage,0,0,0,0,$neww, $newh, $w, $h);
 
	//Sauvegarder la nouvelle image
	imageJpeg($newimage, $newname, 85);
 
 
	// $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
	// $fileTypes  = str_replace(';','|',$fileTypes);
	// $typesArray = split('\|',$fileTypes);
	// $fileParts  = pathinfo($_FILES['Filedata']['name']);
 
	// if (in_array($fileParts['extension'],$typesArray)) {
		// Uncomment the following line if you want to make the directory if it doesn't exist
		// mkdir(str_replace('//','/',$targetPath), 0755, true);
 
		move_uploaded_file($tempFile,$targetVignette);
		move_uploaded_file($tempFile,$targetNormal);
	}else{
		$nomfichier= replace($_FILES['Filedata']['name']);
		$targetFile =  str_replace('//','/',$targetPath) . $nomfichier;
		move_uploaded_file($tempFile,$targetFile);		
	}
 
 
		echo "ok";
	// } else {
	// 	echo 'Invalid file type.';
	// }
}
?> | 
Partager