Changing function in order to accept different types of files
<p>Please, i've posted here a question before, now i've done some progress with some help of course!</p>

<p>I have this code which helps me creeating a jpeg image, now, what i need is to create is an image, png jpg or whatever it is!</p>

<p>I have made some modifications and here is the last result:</p>

<pre><code>function tamano_nuevo_foto($im_or, $ancho_nv, $dir_nv) {
    $ext   = pathinfo($im_or, PATHINFO_EXTENSION);
    $datos = getimagesize($im_or);

    $ancho = $datos[0];

    $alto = $datos[1];

    if ($ancho &gt; $ancho_nv) { //Si la imagen no lelga al máximo no la tocamos.
        $prop    = $alto / $ancho;
        $alto_nv = round($ancho_nv * $prop); //Sacamos la nueva altura
    } else {

        $ancho_nv = $ancho;

        $alto_nv = $alto;
    }

    $im_nv = imagecreatetruecolor($ancho_nv, $alto_nv);

    imagecopyresampled($im_nv, $img, 0, 0, 0, 0, $ancho_nv, $alto_nv, $ancho, $alto);
    switch ($ext) {
        case 'jpg':
            $img = imagecreatefromjpeg($im_or);
            break;
        case 'jpeg':
            $img = imagecreatefromjpeg($im_or);
            break;
        case 'png':
            $img = imagecreatefrompng($im_or);
            break;
        case 'gif':
            $img = imagecreatefromgif($im_or);
            break;
        default:
            $img = imagecreatefromjpeg($im_or);
    }
    imagedestroy($im_nv);
}
</code></pre>

<p>While the original code is:</p>

<pre><code>function tamano_nuevo_foto($im_or, $ancho_nv, $dir_nv) {
    $img   = imagecreatefromstring($im_or);
    $datos = getimagesize($im_or);
    $ancho = $datos[0];
    $alto  = $datos[1];
    if ($ancho &gt; $ancho_nv) { //Si la imagen no lelga al máximo no la tocamos.
        $prop    = $alto / $ancho; /* Calculo la proporcion entre la or y la nv (lo miltiplicamos por mil para evitar problemas con decimales */
        $alto_nv = round($ancho_nv * $prop); //Sacamos la nueva altura
    } else {
        $ancho_nv = $ancho;
        $alto_nv  = $alto;
    }
    $im_nv    = imagecreatetruecolor($ancho_nv, $alto_nv);
    imagecopyresampled($im_nv, $img, 0, 0, 0, 0, $ancho_nv, $alto_nv, $ancho, $alto);
    imagejpeg($im_nv, $dir_nv);
    imagedestroy($im_nv);
}
</code></pre>

<p>The function creates like this:</p>

<pre><code>$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetPath =  str_replace('//','/',$targetPath);
$targetFile =  $targetPath . $_FILES['Filedata']['name'];
tamano_nuevo_foto($tempFile, 800, $targetFile);
</code></pre>
