Bonsoir,
j'ai un nouveau problème je n'arrive pas à uploader une nouvelle image sans recharger la page, ni ajouter une image quand du texte est saisi j'y ai passé la journée....
<?php
$errors= null;
$destpath='./uploads/';
if(!file_exists($destpath) || !is_dir($destpath)){
$destpath=mkdir($destpath);
}else{
chmod($destpath,0755);
}
/*effacemment de la prevu*/
if(isset($_GET['del']) && (string)$_GET['del']!=''){
$filesext=end(explode('.',$_GET['del']));
$extensions_autorisees = array('jpg','jpeg','pjpg','pjpeg','jpg','png','gif','tiff');
if(in_array($filesext,$extensions_autorisees)){
}else{
$errors.='PAS BON !';
exit($errors);
}
$file=$_GET['del'];
$file1=end(explode('/',$file));
$file=$destpath.'/'.$file1;
if(file_exists($file) && $file!='index.php' && $file!='.htaccess'){
if(@unlink($file)){
//echo $file1.' efface
';
//sleep(2);
header('Location: index.php');exit;
}else{
//rien
}
}else{
//rien
}
}else{
//rien
}
?>
header:
<!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" />
<link href="../default/style.css" rel="stylesheet" title="Style" type="text/css" />
<title>Document sans titre</title>
<head>
<script type="text/javascript">
<!--
function urldecode (str) {
//http://phpjs.org/functions/urldecode:572
return decodeURIComponent((str + '').replace(/\+/g, '%20'));
}
function uploadInit() {
// Je pré-charge l'image
var oLoading = new Image();
oLoading.src = "loading.gif";
}
function uploadRun() {
document.getElementById("uploadStatus").innerHTML="";
document.getElementById("uploadForm").submit();
document.getElementById("uploadSubmit").disabled=true;
return true;
}
function uploadEnd(sError,sPath) {
if(sError=='ok'){
document.getElementById('uploadStatus').innerHTML='
[?del='+urldecode(sPath)+' Delete]';
document.getElementById("uploadSubmit").disabled=flase;
}else{
document.getElementById("uploadStatus").innerHTML='';
document.getElementById("uploadSubmit").disabled=false;
}
}
//-->
</script>
<script>
function goTextarea(variable){
//alert(variable);
document.getElementById("message").innerHTML = "";
}
</script>
<script language="javascript" type="text/javascript" src="files/checkbb.js"></script>
FORM:
</head>
<form name="formulaire">
Entrez un texte :
<textarea src="#" onClick="pre_parse('message', 'prev_text', 'prev_box');" onKeyUp="pre_parse('message', 'prev_text', 'prev_box');" id="message" name="message" rows="10" cols="100"></textarea>
</form>
<form id="uploadForm" enctype="multipart/form-data" action="index.php" target="_self" method="post" value="2097152">
<?php
$uppath='./uploads/';
$result=scandir($uppath);
$host='http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$host=str_replace('index.php','',$host);
$host=$host.$uppath;
$v=null;
foreach($result as $k => $v){
if($v=='..' || $v=='.' || $v=='Thumbs.db'|| $v=='index.php'){
$v.='';
}else{
echo ',
,
<hr>';
}
}
?>
</form>
<!-- -->
<?php
/******************************************************************************/
if(isset($_FILES['uploadFile'])){
$filename = $_FILES['uploadFile']['name'];
$path = pathinfo($filename);
$filesext = $path['extension'];
$filesext = strtolower($filesext);
$extensions_autorisees = array('jpg','jpeg','pjpg','pjpeg','jpg','png','gif','tiff');
if ($_FILES['uploadFile']['error'] <= 0){
}else{
$errors.='Erreur lors de l\'upload image
';
//exit($errors);
}
if ($_FILES['uploadFile']['size'] <= 2097152){
}else{
$errors.='L\'image est trop lourde
';
//exit($errors);
}
if(in_array($filesext,$extensions_autorisees)){
}else{
$errors.='Le type MIME de l\'image n\'est pas bon
';
//exit($errors);
}
$img = @getimagesize($_FILES['uploadFile']['tmp_name']);
// print_r($img);
if($errors===null && $filesext==='jpg' && ($img['mime']==='image/jpg' || $img['mime']==='image/jpeg' || $img['mime']==='image/pjpeg')){
$jpgimg = imagecreatefromjpeg($_FILES['uploadFile']['tmp_name']);
$tjpgimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tjpgimg[1] * (($newlarg)/$tjpgimg[0])) );
$newjpgimg = imagecreatetruecolor($newlarg,$newhaut) or die ("Erreur");
imagecopyresampled($newjpgimg,$jpgimg,0,0,0,0,$newlarg,$newhaut,$tjpgimg[0],$tjpgimg[1]);
imagedestroy($jpgimg);
$filerename = 'fichier_du_'.time().'.'.$filesext;
imagejpeg($newjpgimg,$_SESSION['f']=$f=$destpath.'/'.$filerename,100);
$f='<script>uploadEnd(\'ok\',\''.urlencode($f).'\');</script>';
}
elseif($errors===null && $filesext==='png' && ($img['mime']==='image/png' || $img['mime']==='image/x-png')){
$pngimg = imagecreatefrompng($_FILES['uploadFile']['tmp_name']);
$tpngimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tpngimg[1] * (($newlarg)/$tpngimg[0])) );
$newpngimg = imagecreatetruecolor($newlarg,$newhaut) or die ("Erreur");
imagecopyresampled($newpngimg,$pngimg,0,0,0,0,$newlarg,$newhaut,$tpngimg[0],$tpngimg[1]);
imagedestroy($pngimg);
$filerename = 'fichier_du_'.time().'.'.$filesext;
imagepng($newpngimg,$_SESSION['f']=$f=$destpath.'/'.$filerename);
$f='<script>uploadEnd(\'ok\',\''.urlencode($f).'\');</script>';
}
elseif($errors===null && $filesext==='gif' && $img['mime']==='image/gif'){
$pngimg = imagecreatefromgif($_FILES['uploadFile']['tmp_name']);
$tpngimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tpngimg[1] * (($newlarg)/$tpngimg[0])) );
$newpngimg = imagecreatetruecolor($newlarg,$newhaut) or die ("Erreur");
imagecopyresampled($newpngimg,$pngimg,0,0,0,0,$newlarg,$newhaut,$tpngimg[0],$tpngimg[1]);
imagedestroy($pngimg);
$filerename = 'fichier_du_'.time().'.'.$filesext;
imagegif($newpngimg,$_SESSION['f']=$f=$destpath.'/'.$filerename);
$f='<script>uploadEnd(\'ok\',\''.urlencode($f).'\');</script>';
}
else{
$f=$errors;
}
}else{
}
?>
<script type="text/javascript">
<!--
window.top.window.uploadEnd("<?php echo $error; ?>", "<?php echo $destpath. $filerename; ?>");
//-->
</script>
a combat sans honneur vainqueur sans gloire!!