Har googlat lite nu men hittar inte det jag söker.
Jag skulle behöva ett gratis bilduppladdningsskript som dels laddar upp bilden och dels skapar en komprimerad och resizad thumb.
Språket är PHP och all information ska sparas i XML.
1 svar · 1 676 visningar · startad av Jonny Strömberg
Har googlat lite nu men hittar inte det jag söker.
Jag skulle behöva ett gratis bilduppladdningsskript som dels laddar upp bilden och dels skapar en komprimerad och resizad thumb.
Språket är PHP och all information ska sparas i XML.
Välkommen till webForum! :)
Här är två exempel på hur filuppladdning resp. storleksförändring av bild i php kan göras. Hämtad ur php-manualen för "Handling file uploads" resp. funktionen "imagecopyresampled".
Filuppladdning:
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>
Ersätt _URL_ med namnet på din php-fil som tar hand om filuppaddningen.
Storleksförändring av bild, resampling an image proportionally. This example will display an image with the maximum width, or height, of 200 pixels:
<?php
// The file
$filename = 'test.jpg';
// Set a maximum height and width
$width = 200;
$height = 200;
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, null, 100);
?>
Beroende på vilken storlek tumnageln ska ha kanske du måste skriva om get new dimensions-delen. Återkom om du inte får ordning på det eller filuppladdningen.