Ma tot chinui de ceva vreme sa realizez un formular care sa dauge in baza de date shi sa afisheze pe site.
In momentul in care fac up-load la o anumita poza vreau ca scriptul sa`mi redenumeasca poza dupa id , s`o redimenzioneze, si cel mai important sa`mi copie "noua" poza (redimensionata shi redenumita ) intr`un anumit folder in cazul meu "pics/".
$max=0;
$idPoza="select * from sony";
$idPoza1=mysql_query($idPoza);
while($row= mysql_fetch_array($idPoza1))
{
if($row['id']>$max)
{
$max=$row['id'];
}
}
//Functia upload start
if ($_FILES['logo']['name']!= "")
{
$newimg1 = ''.$max.''.".jpg";
$adresaImagine= "pics/";
move_uploaded_file ( $_FILES['logo']['tmp_name'], $adresaImagine. $newimg1 );
header("location: index.php");
ce imi lipseshte ptr a face redimensiona, redenumi , shi copia poza in folderul pics ca dupa ce fac upload in folderul respectiv nu gasesc nimic!
Redenumire/redimensionare/copiere ptr a afisa in PHP ??
Moderatori: Zamolxe, Moderatori
- maniac0man
- PHPRomania Supporter
- Mesaje: 13
- Membru din: Vin Aug 31, 2007 9:30 pm
imagecreatetruecolor,imagecopyresampled / rename / copy
toate le gasesti la www.php.net ...cauta niste exemple incarca sa refaci scriptul si zine ce nu merge.
aaa si inca cv nu mai crea 2 topic-uri pt acelasi subiect...fa unu si urmarestel
toate le gasesti la www.php.net ...cauta niste exemple incarca sa refaci scriptul si zine ce nu merge.
aaa si inca cv nu mai crea 2 topic-uri pt acelasi subiect...fa unu si urmarestel
say what?...
Vezi daca poti folosi functia asta.
Codul il public under GPL or LGPL license. Adica free to use.
Codul il public under GPL or LGPL license. Adica free to use.
Cod: Selectaţi tot
/** Move uploaded image, check the image, resize the image, convert the image to jpg.
* Returns false on failure or true on success.
*
*/
function Move_UploadedImage($pOriginalFile,$pTempFile,$pFinalFile,$pMaxSize,$pResizeAlways,$pQuality=75)
{
// Move uploaded file
if ( !move_uploaded_file( $pOriginalFile, $pTempFile ) )
{
return false;
}
// Get image informations
$tempResult = getimagesize($pTempFile);
if ( $tempResult == false )
{
unlink($pTempFile);
return false;
}
$tempSrcWidth = $tempResult[0];
$tempSrcHeight = $tempResult[1];
$tempSrcType = $tempResult[2];
// Load image from file
if ( $tempSrcType == 2 )
{
// JPG
$tempImgSrc = @imagecreatefromjpeg($pTempFile);
} elseif ( $tempSrcType == 1 )
{
// GIF
$tempImgSrc = @imagecreatefromgif($pTempFile);
} elseif ( $tempSrcType == 3 )
{
// PNG
$tempImgSrc = @imagecreatefrompng($pTempFile);
} else
{
unlink($pTempFile);
return false;
}
// Delete original file
unlink($pTempFile);
// Check
if (!$tempImgSrc) return false;
// See if we need to resize the image
if ( $pResizeAlways || $tempSrcWidth > $pMaxSize || $tempSrcHeight > $pMaxSize )
{
// Compute image size
if($tempSrcWidth > $tempSrcHeight)
{
$tempDiv = $tempSrcWidth / $pMaxSize;
} else
{
$tempDiv = $tempSrcHeight / $pMaxSize;
}
$tempDestWidth = $tempSrcWidth / $tempDiv;
$tempDestHeight = $tempSrcHeight / $tempDiv;
// Create destination image
$tempImgDest = @imagecreatetruecolor($tempDestWidth,$tempDestHeight);
if ( !$tempImgDest )
{
imagedestroy($tempImgSrc);
return false;
}
// Copy source to destination
if ( !imagecopyresampled($tempImgDest,$tempImgSrc,0,0,0,0,$tempDestWidth, $tempDestHeight,$tempSrcWidth,$tempSrcHeight) )
{
imagedestroy($tempImgSrc);
imagedestroy($tempImgDest);
return false;
}
// Save destination
imagejpeg($tempImgDest,$pFinalFile,$pQuality);
// Destroy destination
imagedestroy($tempImgDest);
} else
{
// Save
imagejpeg($tempImgSrc,$pFinalFile,$pQuality);
}
// Destroy source
imagedestroy($tempImgSrc);
// OK
return true;
}
Cine este conectat
Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 43 vizitatori

