Resize poza la dimensiune fixa
Scris: Sâm Ian 19, 2013
Folosesc acest cod de incarcare dar doresc sa si redimensioneze pozele din marimea lor naturala sa le redimensioneze in 300 pe 300 . Nu sa decupeze sa le redimensioneze !
Cod: Selectaţi tot
<?php
include('conectare.php');
$uploadpath = 'poza-profil/'; // directory to store the uploaded files
$max_size = 10000; // maximum file size, in KiloBytes
$alwidth = 10000; // maximum allowed width, in pixels
$alheight = 10000; // maximum allowed height, in pixels
$allowtype = array('jpg', 'jpe'); // allowed extensions
if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
$sepext = explode('.', strtolower($_FILES['fileup']['name']));
$type = end($sepext); // gets extension
$nume = strip_tags($_POST['nume']); // nume_utilizator
$id = 0; // valoare initiala, in caz ca nu e gasit vreun "id"
$sql = mysql_query("SELECT `id` FROM `membri` WHERE `nume` = '$nume' LIMIT 1");
$sql = mysql_fetch_assoc($sql);
if(!empty($sql['id']))
{
$id = $sql['id'];
}
$uploadpath = $uploadpath . $id. '.'. $type; // gets the file name
list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); // gets image width and height
$err = ''; // to store the errors
// Checks if the file has allowed type, size, width and height (for images)
if(!in_array($type, $allowtype)) $err .= '<div id=eroare>Poza: <b>'. $_FILES['fileup']['name']. '</b> nu are tipul de extensie acceptata - jpg sau jpe.</div>';
if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<div id=eroare>Marimea maxima trebuie sa fie de: '. $max_size. ' KB.</div>';
if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<div id=eroare>Marimea maxima a inaltimii si latimii trebuie sa fie: '. $alwidth. ' x </div>'. $alheight;
// If no errors, upload the image, else, output the errors
if($err == '') {
if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) {
echo '';
}
else echo '<div id=eroare>Poza nu a putut fi incarcata. Incearca alta poza.</div>';
}
else echo $err;
}
?>