---
title: "Bilduppladdning - PHP/XML"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/148062-bilduppladdning-php-xml"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "Jonny Strömberg"
published: "2006-06-14T11:22:53.000Z"
updated: "2006-06-19T07:18:44.000Z"
replies: 1
views: 1676
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/148062-bilduppladdning-php-xml"
---

# Bilduppladdning - PHP/XML

## #1 — Jonny Strömberg, 2006-06-14T11:22Z

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.

Permalänk: https://www.webforum.nu/p/148062

## #2 — henke, 2006-06-19T07:18Z

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:

```php
<!-- 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
<?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.

Permalänk: https://www.webforum.nu/p/1830414

---

Tråden på webben: https://www.webforum.nu/amne/php/148062-bilduppladdning-php-xml
