hi guru's, i found this lil script on the web, and i want it to redo till it accepts ONLY gif files, i dont know how i can restrict it to just accept gifs, all i understand so far is that what i fill in under the "file type check" is whats NOT possible to upload....any ideas for me ?

heres the script, ty in advance

<?php

$site_name = $SERVER['HTTP_HOST'];
$url_dir = "http://".$
SERVER['HTTP_HOST'].dirname($SERVER['PHP_SELF']);
$url_this = "http://".$
SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

$upload_dir = "aanbieding/";
$upload_url = $url_dir."/aanbieding/";

if ($_FILES['userfile']) {
$message = do_upload($upload_dir, $upload_url);
}
else {
$message = "";
}

print $message;

function do_upload($upload_dir, $upload_url) {

$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name']; 
$file_type = $_FILES['userfile']['type'];

$file_size = $_FILES['userfile']['size']; 
$result    = $_FILES['userfile']['error'];
$file_url  = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;

//File Name Check
 if ( $file_name =="") { 
	$message = "Je hebt nog geen foto geselecteerd om te uploaden :)";
	return $message;
}
//File Size Check
else if ( $file_size > 500000) {
    $message = "het bestand is te groot, het is meer dan 500K.";
    return $message;
}



//File Type Check

else if ( $file_type == "image/gif" ) {
$message = "Sorry, ......!!" ;
return $message;
}

$result  =  move_uploaded_file($temp_name, $file_path);
$message = ($result)?"upload van je foto is gelukt" :
	      "er is iets mis gegaan, probeer het later nog eens.";

return $message;

}
?>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
Upload foto´s<input type="file" id="userfile" name="userfile">
<input type="submit" name="upload" value="Upload">
</form>

    From what I can see of the script posted, reverse the test. ie

    if ( $file_type != "image/gif" ) { 
    $message = "Sorry, ......!!" ; 
    return $message; 
    }
    

    The above will only be passed by a GIF file. Any other file will fail.

    To be honest, I'd ditch the function within the script anyway.

    Feed the file array into your function, $farray being the whole file array, $fname the uploaded filename, $ftype is its type headers.

    function do_File_Process($farray, $fname, $ftype)	{
    	global $db;
    	global $IMAGE_DATA;
    	$filemsg = "<p>ORIGINAL FILE<br />$fname $fsize bytes $ftype";
    	$newfile = cleanfilename($fname);
    	$copied = $IMAGE_DATA . $newfile;
    	switch ($ftype)	{
    		case "image/gif":
    			if (!copy($farray, $copied))	{		// <- Save our original
    				$filemsg .= "<br /><b>FILE UPLOAD FAILED</b>.";
    			}	else	{
    				$filemsg .= "<br /><b>FILE UPLOAD COMPLETE</b>.";
    			};
    			break;
    		default:
    			$filemsg .= "<br /><b>INVALID FILE TYPE</b>.";
    	}
    	unlink ($farray);
    	return $filemsg;
    }
    

      thx allot siwis that worked fine, im to new to understand whats actually changed but with the

      if ( $file_type != "image/gif" ) {

      $message = "Sorry, ......!!" ;

      return $message;

      }

      all works like i would have it, thx allot

        Write a Reply...