UPLOAD HELP ????

-upload.php-

[code]

Single File Upload
Select file
[/code]

-rename-
[php]<?php
// Your file name you are uploading
$file_name = $HTTP_POST_FILES[‘ufile’][‘name’];
// random 5 digit to add to our file name
// some people use date and time in stead of random digit
$random_digit=rand(00000,99999);
// spliter
$desh = “.”;
//combine random digit to you file name to create new file name
//use dot (.) to combile these two variables
$new_file_name=$random_digit.$desh.$file_name;
//set where you want to store files
//in this example we keep file in folder upload
//$new_file_name = new upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= “upload/”.$new_file_name;
if($ufile !=none)
{
if(copy($HTTP_POST_FILES[‘ufile’][‘tmp_name’], $path))
{
echo “Successful
”;
//$new_file_name = new file name
//$HTTP_POST_FILES[‘ufile’][‘size’] = file size
//$HTTP_POST_FILES[‘ufile’][‘type’] = type of file
echo “File Name :”.$new_file_name."
";
echo “File Size :”.$HTTP_POST_FILES[‘ufile’][‘size’]."
";
echo “File Type :”.$HTTP_POST_FILES[‘ufile’][‘type’]."
";
echo “<img src=”$path" width=“150” height=“150”>";
}
else
{
echo “Error”;
}
}
?>[/php]

the script needs to look if the files are photos it need to allow (jpg,png,bmp,gif) and block anything else
can any wone help me ??? tnx kevin

Use function getimagesize() to detect file type:

[php]$allowed_types = array(1, 2, 3, 6);
if($inf = getimagesize($path)){
if(in_array($inf[2],$allowed_types)){
// file is valid gif, jpeg, png or bmp
}
}[/php]

now i got this notworking ?

[php]

<?php if ($HTTP_POST_FILES['type']!="jpg"){ echo "jpg only allowed";} else { $file_name = $HTTP_POST_FILES['ufile']['name']; $random_digit=rand(00000,99999); $desh = "."; $new_file_name=$random_digit.$desh.$file_name; $path= "upload/".$new_file_name; if($ufile !=none) { if(move_uploaded_file($HTTP_POST_FILES['ufile']['tmp_name'], $path)) { echo "Successful
"; echo "File Name :".$new_file_name."
"; echo "File Size :".$HTTP_POST_FILES['ufile']['size']."
"; echo "File Type :".$HTTP_POST_FILES['ufile']['type']."
"; echo ""; } else { echo "Error"; } } } ?>[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service