All pastes #518477 Raw Edit

sadjasudhasd

public php v1 · immutable
#518477 ·published 2007-05-29 10:10 UTC
rendered paste body
<?php if (isset($_FILES['uplfile'])) {        $upload_dir = 'upload/';      $filetypes = 'jpg,gif,png';       $maxsize = (1024*1024);        if(empty($_FILES['uplfile']['name']))        die('Ingen fil har valts');       if($_FILES['uplfile']['size'] > $maxsize)        die('Filen du valde är för stor. Maxstorleken är '.(string)($maxsize/1024).' KB.');        $types = explode(',', $filetypes);    $file = explode('.', $_FILES['uplfile']['name']);    $extension = $file[sizeof($file)-1];    if(!in_array(strtolower($extension), $types))        die('Du har en felaktig filtyp. Endast .jpg, .gif och .png är tillåtet!');        $bokstav = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6');    $thefile = $_FILES['uplfile']['name'];    while (file_exists($upload_dir.$thefile)) { $img = $bokstav[rand(0, count($bokstav)-1)].$thefile; }        if (is_uploaded_file($_FILES['uplfile']['tmp_name']) && move_uploaded_file($_FILES['uplfile']['tmp_name'],$upload_dir.$thefile)) {     	    echo 'Filen laddades upp!';        } else {        echo 'Ett fel uppstod och filen kunde inte laddas upp.';          }}else{  ?>    <form action="./?p=upload" method="post" enctype="multipart/form-data">    Fil:&nbsp;<input type="file" name="uplfile"><br>    <input type="submit" value="Ladda upp filen">    </form>  <?php}?><br>Listing<br><?phpif ($handle = opendir('upload/')) {     while (false !== ($file = readdir($handle))) {		$erase = array('.','..','index.php');			if ( in_array ($file, $erase) ) 		{				} else {        echo '<a href="upload/'.$file.'" target="_blank">' . $file . '</a><b> ' . round(filesize("upload/".$file)/1024,1) . '</b> Kb<br>';		}    }       closedir($handle);}?>