Archive | PHP
Limiter le débit d’un fichier en upload
Publié le 26 juillet 2015 | Par adminblog | Commenter
Utilitaire pour limiter la bande passante …
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  | 
						<?php // filename that the user gets for downloading $download_file = 'file-to-download.zip'; // set the download rate limit $download_rate = 20.5; //=> 20,5 kb/s header('Cache-control: private'); header('Content-Type: application/octet-stream'); header('Content-Length: '.filesize($download_file)); header('Content-Disposition: filename='.$download_file); flush(); // open file stream $file = fopen($download_file, "r"); while(!feof($file)) { // send the current file part to the browser print fread($file, round($download_rate * 1024)); // flush the content to the browser flush(); sleep(1); } fclose($file);} ?>  | 
					
Annuaire de liens php
Publié le 16 juillet 2015 | Par adminblog | Commenter
Tutoriaux / Lessons http://www.w3schools.com/php/ http://www.webmonkey.com/2010/02/php_tutorial_for_beginners/ http://www.thesitewizard.com/php/ http://sylvie-vauthier.developpez.com/tutoriels/php/grand-debutant/ Banques de scripts http://scripts.toucharger.com/scripts/php/ http://www.phpsources.org/ressources-php.htm vhttp://www.ultraphp.net/ http://www.actugaming.net/files/file/27-30-scripts-php-de-base/ http://www.monsitegratuit.com/scripts/scripts.php?code=23 http://www.easy-script.com/ http://www.scripts.com/ http://sourceforge.net/ https://code.google.com/hosting/search?q=label%3aPHP http://lamicro.free.fr/Dossiers/Scripts/ http://www.scriptol.fr/webmaster/ http://www.supportduweb.com/scripts_tutoriaux-1-php-mysql.html http://www.phpjabbers.com/free-php-scripts.php https://www.hscripts.com/scripts/php/ http://www.scriptdungeon.com/php_scripts.php http://proxy2.de/scripts.php http://codes-sources.commentcamarche.net/php-5 http://webmaster.web-soluces.net/php/ http://www.phpkode.com/ PDF / cours http://www.misfu.com/information-cours-tutos-tutoriaux-PHP.html http://cours-pdf.com/cours-informatique/web.html http://cours.toucharger.com/cours/informatique/programmation/php/ http://julien23.free.fr/pub/PHP_v1r44.pdf http://framasoft.net/IMG/pdf/initiation_php.pdf http://arpinux.org/public/books-man/php.pdf http://www.cours-gratuit.com/cours-php/ Scripts utiles Livre d’or http://www.chopinscript.codissimo.fr/ http://www.phpjunkyard.com/php-guestbook-script.php http://www.alexguestbook.net/e_index.html http://www.gentlesource.com/guestbook/ http://www.phpjabbers.com/free-guestbook-script/ http://www.maianguestbook.com/ http://www.dbscripts.net/guestbook/ Annuaires Petites annonces Tchat room CMS Sondages Commentaires
Connection à MySql avec PHP
Publié le 14 juillet 2015 | Par adminblog | Commenter
Se connecter à MySql méthode Old School ! Mieux utiliser PDO en 2015
| 
					 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  | 
						<?php // Déclaration des paramètres de connexion $host = "la_machine";   // Généralement la machine est localhost // c'est-a-dire la machine sur laquelle le script est hébergé $user = "votre_login"; $bdd = "Nom_de_la_base_de_donnees"; $passwd  = "Mot_de_passe"; // Connexion au serveur mysql_connect($host, $user,$passwd) or die("erreur de connexion au serveur"); mysql_select_db($bdd) or die("erreur de connexion a la base de donnees"); /*connection établie si pas de message d'erreurs*/ ?>  | 
					
Une astuce consiste à travailler dans un jeu de caractères fixé COMME utf-8 qui est très universel. Votre éditeur de programmation (pspad,notepad++ …) doit toujours travailler encoder,coder en UTF-8 sans BOM puis il faut négocier entre PHP et MySql en utf-8 et définir le charset de votre HTML en utf-8. Vous n’aurez pas de problèmes avec les accents dans l’affichage ainsi […]
Image resizer v1
Publié le 14 juillet 2015 | Par adminblog | Commenter
Fonction utile pour redimensionner des images gif, jpg et png. Utilisable avec des formulaires de transfert de fichiers.
| 
					 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103  | 
						<?php function redimPhoto($img,$x=125,$y=75){     # L'emplacement de l'image à redimensionner. L'image peut être de type jpeg, gif ou png      $big  = $img ;     $file = $img ;     $size = getimagesize($file);      /*homothetie peu être dévalidée*/     $w=$size[0];     $h=$size[1];     if($h>$w){     $zoom=$x/$h;     $y=$y;     $x=$w*$zoom;     }else{     $zoom=$x/$w;     $x=$x;     $y=$h*$zoom;     }     /*fin homothetie*/     if (isset($size)>0) {      //echo 'Image en cours de redimensionnement...';      if ($size['mime']=='image/jpeg' ) {     //echo 'jpg';      $img_big = imagecreatefromjpeg($file); # On ouvre l'image d'origine      $img_new = imagecreate($x, $y);      # création de la miniature      $img_mini = imagecreatetruecolor($x, $y)      or   $img_mini = imagecreate($x, $y);      // copie de l'image, avec le redimensionnement.      imagecopyresized($img_mini,$img_big,0,0,0,0,$x,$y,$size[0],$size[1]);      imagejpeg($img_mini,$file );      }      elseif ($size['mime']=='image/png' ) {     //echo 'png';       $img_big = imagecreatefrompng($file); # On ouvre l'image d'origine      $img_new = imagecreate($x, $y);      # création de la miniature      $img_mini = imagecreatetruecolor($x, $y)      or   $img_mini = imagecreate($x, $y);      // copie de l'image, avec le redimensionnement.      imagecopyresized($img_mini,$img_big,0,0,0,0,$x,$y,$size[0],$size[1]);      imagepng($img_mini,$file );      }      elseif ($size['mime']=='image/gif' ) {      //echo 'gif';      $img_big = imagecreatefromgif($file); # On ouvre l'image d'origine      $img_new = imagecreate($x, $y);      # création de la miniature      $img_mini = imagecreatetruecolor($x, $y)      or   $img_mini = imagecreate($x, $y);      // copie de l'image, avec le redimensionnement.      imagecopyresized($img_mini,$img_big,0,0,0,0,$x,$y,$size[0],$size[1]);      imagegif($img_mini,$file );      }      return $file;     //echo 'Image redimensionnée !';      }else{     return false;     }     //fin function image thumb     }     /*     avec un formulaire     <form action="fichier_ou_est_la_fonction_redim.php" method="POST" enctype="multipart/form-data" />     <input type="file"  name="Photo" class="form">';     <input type="submit" value="Modifier" class="form"  />';     </form>     dans  fichier_ou_est_la_fonction_redim.php     $image=$_FILES['Photo']['tmp_name']     ...     */     /*autre utilisation*/     $image='une_image.jpg';     //sauver originale     copy($image,$normal='n_'.$image);     //sauver une miniature     $redim=redimPhoto($image);     copy($redim,$petit='p_'.$redim);     //supression originale     //unlink($image);  ?>   | 
					
Click counter
Publié le 13 juillet 2015 | Par adminblog | Commenter
| 
					 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  | 
						<?php		 /* Name: hits counter Description:it's a simple hit counter which keeps track your  visitor to the site ,it also keeps count of the perticular ip and  its count,it also keeps the last visited page */ ## before using this code you must make the following table in your database #Table name: stats # fields: Ipaddress(varchar(150)),host(varchar(150)),browser(varchar(150)),referer(varchar(150)),filename(varchar(150)). # table name: hits # fields: ipaddress(varchar(150)),count(int(11)) ############################################### global $dblink,$PHP_SELF; $ip = getenv("REMOTE_ADDR"); $host = getenv("HTTP_HOST"); $browser = getenv("HTTP_USER_AGENT"); $referer = getenv("HTTP_REFERER"); $sql = "SELECT ipaddress FROM stats WHERE ipaddress = '$ip'"; #### TO DO ###################### 	# make the connection to your database here 	$result = @mysql_query($sql, $dblink); $num = mysql_num_rows($result); 	if( $num == 0 ) { 	$sql ="INSERT INTO stats(ipaddress,host,browser,referer,filename) VALUES('$ip', '$host', '$browser', '$referer','$PHP_SELF')"; 	$result=mysql_query($sql,$dblink);  	$sql1="INSERT INTO hits(ipaddress,count) VALUES('$ip',1)"; 	$result1=@mysql_query($sql1,$dblink); 	$text="you had a new visitor from IP: $ip, Host: $host Browser: $browser Referer: $referer"; 	 if ($result) 		{ 		mail("abc@abc.com", "You had a new visitor",$text, "FROM: stats@abc.com"); 		} 	}else{ 	$sql = "UPDATE hits SET count = count + 1 where ipaddress='$ip'"; 	$result =@mysql_query($sql, $dblink) ; 	$sql2 = "UPDATE stats SET filename ='$PHP_SELF' where ipaddress='$ip'"; 	$result2 =@mysql_query($sql2, $dblink) ; } ?>  | 
					
Multiples upload files
Publié le 13 juillet 2015 | Par adminblog | Commenter
| 
					 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  | 
						<?php $numoffiles = 5; 	echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">' ; 	for ($i = 1; $i<=$numoffiles; $i++) 	{ 		echo 'Image'.$i.': <input type="file" name="file[]" size="30" style="cursor:hand;"/> <br /> '; 	} 	echo '<input type="submit" name="action" value="Upload" />'; 	echo '</form>'; 	if(isset($_POST['action'])) 	{ 		$uploaddir = 'C:/PHP/uploadtemp/'; 		for ($i =0; $i<$numoffiles; $i++) 		{ 			$filename = $_FILES['file']['name'][$i]; 			$filetmp = $_FILES['file']['tmp_name'][$i]; 			$filesize = $_FILES['file']['size'][$i]; 			$filetype = $_FILES['file']['type'][$i]; 			$ext = substr(strrchr($filename, "."),1); 			$conf = $uploaddir . $filename; 			$filepath = $uploaddir . $filename; 		if ($filename != "") 		{ 			if (!file_exists($filepath)) 			{ 				if ($ext == "jpg" || $ext == "gif" || $ext == "tiff" || $ext == "png" || $ext == "bmp") 				{ 					if($filesize < "500000") 					{ 						$upload = move_uploaded_file($filetmp, $filepath); 						echo '<font color=blue>'. $filename . ' <i>was successfully uploaded...</font><br />';	 					} 					else 					{ 						echo '<font color=red>'.$filename . ' <i>greater than the maximum file size allowed...</font><br />'; 					} 				} 				else 				{ 					echo '<font color=red>'. $filename . ' <i>is invalid file type...</font><br />'; 				}	 			} 			else 			{ 				echo $filename . ' <i>already exists...</i><br />'; 			} 		} 		} 	} ?>   | 
					
Force download
Publié le 13 juillet 2015 | Par adminblog | 1 commentaire
| 
					 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  | 
						<?php /*change this to your file location*/ $file_url="http://mywebsite.com/mydirectory/somefile.zip"; /*end change this*/ if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {     header('Content-Type: "application/octet-stream"');     header('Content-Disposition: attachment; filename="'.basename($file_url).'"');     header('Expires: 0');     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');     header("Content-Transfer-Encoding: binary");     header('Pragma: public');     header("Content-Length: ".filesize($file_url)); } else {     header('Content-Type: "application/octet-stream"');     header('Content-Disposition: attachment; filename="'.basename($file_url).'"');     header("Content-Transfer-Encoding: binary");     header('Expires: 0');     header('Pragma: no-cache');     header("Content-Length: ".filesize($file_url)); } readfile($file_url); ?>  | 
					
Commentaires récents