Pagina 1 din 1

Adaugare utilizator intr-un fisier tip text

Scris: Joi Dec 15, 2011
de MelecaCristian
Buna useri marplo ... am o mica dilema cu un script php de upload ... problema este urmatoarea vrea sa inregistreze cateva date din scriptul de mai jos si anume :
Cand un user vrea sa upload-eze o poza sa ii fie inregistrat numele de utilizator care se gaseste in url ... se detecteaza cu GET_['ID'] + in acelas timp sa inregistreze si datele de la $_GET['cat'] + fiserul care il urca ... scriptul nu tine minte numele real al pozei de exemplu "zapada.jpg" il transforma in "1321141233.jpg" iar acel cod sa fi inregistrat intr-un fisier numit sesiuni.txt nu stiu unde anume sa introduc scriptul de adaugare date in fisierul text ... multumesc de ajutor

Cod de adaugare tip text (needitat pt ca nu stiu):

Cod: Selectaţi tot

<?php 
 $File = "sesiuni.txt"; 
 $Handle = fopen($File, 'w');
 ?>
Cod de upload imagini + transformarea numelui :

Cod: Selectaţi tot

<?php 
// Citire Date Cateogrie + User-ul curent
$da = $_GET['cat'];
$user = $_GET['ID'];
?>

<?php
 define ("MAX_SIZE","10000"); 

//This function reads the extension of the file. It is used to determine if the file  is an image by checking the extension.
 function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }

//This variable is used as a flag. The value is initialized with 0 (meaning no error  found)  
//and it will be changed to 1 if an errro occures.  
//If the error occures the file will not be uploaded.
 $errors=0;
//checks if the form has been submitted
 if(isset($_POST['Submit'])) 
 {
 	//reads the name of the file the user submitted for uploading
 	$image=$_FILES['image']['name'];
 	//if it is not empty
 	if ($image) 
 	{
 	//get the original name of the file from the clients machine
 		$filename = stripslashes($_FILES['image']['name']);
 	//get the extension of the file in a lower case format
  		$extension = getExtension($filename);
 		$extension = strtolower($extension);
 	//if it is not a known extension, we will suppose it is an error and will not  upload the file,  
	//otherwise we will do more tests
 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
 		{
		//print error message
 			echo '<h1>Nu e imagine sau nu ii cunosc extensia</h1>';
 			$errors=1;
 		}
 		else
 		{
//get the size of the image in bytes
 //$_FILES['image']['tmp_name'] is the temporary filename of the file
 //in which the uploaded file was stored on the server
 $size=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
{
	echo '<h1>Ai Depasit Limita</h1>';
	$errors=1;
}

//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname= "$da/".$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied) 
{
	echo '<h1>Eroare Incarcare Fotografie</h1>';
	$errors=1;
}}}}

//If no errors registred, print the success message
 if(isset($_POST['Submit']) && !$errors) 
 {
 	echo "<h1>A fost Incarcata Imaginea,poti vedea poza ta <a href='http://.....php?yc=$da'>aici</a></h1><br><br>";
 }

 ?>

 <!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" -->

<h3>Incarca imaginile tale in categoria \<?=$da?></h3>
 <div style="width:800px;height:160px;border:2px outset red;">
<table cellspacing="0" border="0" cellpadding="0">
<tr valign="top" align="left">
<td width="250"><p>
<form name="newad" method="post" enctype="multipart/form-data"  action="">
 <table>
 	<tr><td><input type="file" name="image"></td></tr>
 	<tr><td><input name="Submit" type="submit" value="Trimite Imaginea"></td></tr>
 </table>	
 </form>

Adaugare utilizator intr-un fisier tip text

Scris: Sâm Dec 17, 2011
de GarryOne
scriptul e aiurea
se verifica extensia jpeg, jpg, png cu &&, adica el verifica daca este jpeg, png, jpg in acelasi timp, ceea ce nu va fi niciodata
extensia se poate afla cu $_FILES['fisier']['type']
sau cu path_info, ci nu cu 10 linii de cod
oricum..

Cod: Selectaţi tot

<?php 
$File = "sesiuni.txt"; 
$content = "$user \r\n $da \r\n$newname \r\n\r\n\r\n"
$Handle = fopen($File, 'w');
fwrite($Handle, $content);
fclose($Handle);
?>