View Single Post
  #4 (permalink)  
Old 11-14-04, 03:35 PM
Dyllon Dyllon is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
This should work

PHP Code:

/*== BEGIN FUNCTIONS ==*/

    
function getFileExtension($str) {
        
$i strrpos($str,".");
        if (!
$i) { return ""; }

        
$l strlen($str) - $i;
        
$ext substr($str,$i+1,$l);

        return 
$ext;
    }

    function 
uploadImage($imgfile$imgfile_name) {
   
             
/*== upload directory where the file will be stored 
          relative to where script is run ==*/
    
           
$uploaddir $_SERVER['DOCUMENT_ROOT'] . "/blah/ad_images/";
    
        
// Use this if you want to restrict image dimensions
        
$imagesize getimagesize($imgfile);
        
$imagewidth $imagesize[0];
        
$imageheight $imagesize[1];
             
$maxwidth 200;
        
$maxheight 200;

        
/*== get file extension  ==*/
        
$pext getFileExtension($imgfile_name);
        
$pext strtolower($pext);
        
        if(
$imagewidth $maxwidth || $imageheight $maxheight
        {
            
//display error for image being too large 
            //remember to remove this condition if your not limiting the image dimesnions
        
}
        elseif ((
$pext != "jpg")  && ($pext != "jpeg")  && ($pext != "gif"))
        {
            
//display error for invalid image extension
        
}
        else {
            
/*== setup final file location and name ==*/
            /*== change spaces to underscores in filename  ==*/
            
$rand_numb md5(uniqid(microtime())); 
            
$neu_name "$rand_numb"."$imgfile_name";
            
$final_filename str_replace(" ""_"$neu_name);
            
$newfile $uploaddir "/$final_filename";
    
            if (
is_uploaded_file($imgfile))
            {

                   
/*== move file to proper directory ==*/
                   
if (!copy("$imgfile","$newfile")) 
                   {
                      
/*== if an error occurs the file could not
                       be written, read or possibly does not exist ==*/
                      
print "Error Uploading File.";
                   }
             }

            if (
is_uploaded_file($imgfile))
            {
                
$Image $final_filename;
                
$Image stripslashes($Image);
                return 
$Image;
            }
        }
    }
    
/*== END FUNCTIONS ==*/

                
$mm=$_POST['mm'];
                
$dd=$_POST['dd'];
                
$yyyy=$_POST['yyyy'];
                
$main_title=$_POST['main_title'];
                
$category_name=$_POST['category_name'];
                
$bus_name=$_POST['bus_name'];
                
$personal_name=$_POST['personal_name'];
                
$pword=$_POST['pword'];
                
$phone=$_POST['phone'];
                
$address=$_POST['address'];
                
$city=$_POST['city'];
                
$zip_code=$_POST['zip_code'];
                
$email=$_POST['email'];
                
$web_url=$_POST['web_url'];
                
$mon_hours=$_POST['mon_hours'];
                
$tue_hours=$_POST['tue_hours'];
                
$wed_hours=$_POST['wed_hours'];
                
$thu_hours=$_POST['thu_hours'];
                
$fri_hours=$_POST['fri_hours'];
                
$sat_hours=$_POST['sat_hours'];
                
$sun_hours=$_POST['sun_hours'];
                
$location=$_POST['location'];
                
$desc=$_POST['desc'];
                
$info=$_POST['info'];
                
$plan_agreement=$_POST['plan_agreement'];
                
$list_plan=$_POST['list_plan'];
                
$confirm_question=$_POST['confirm_question'];
                
$confirm_answer=$_POST['confirm_answer'];
                
$bus_name=addslashes($bus_name);
                
$location=addslashes($location);
                
$desc=addslashes($desc);
                
$info=addslashes($info);
                
                
//if photo is supplied upload and get the new random name
                //otherwise set $photo to default image
                
if (!empty($photo)) {
                    
$photo uploadImage($photo$photo_name);
                }
                else {
                    
$photo "no_image.gif";
                }

include(
"siteinfo.php");
require(
"rand_num.php");
include(
"connect.php");
$conn mysql_connect(localhost,"$dbuser","$dbpass") or die ("Could not connect MySQL");
mysql_select_db("$db") or die ("Could not open database");
$query "INSERT INTO listings VALUES('','$mm', '$dd', '$yyyy', '$main_title','$category_name','$bus_name','$perso  nal_name','$pword','$phone','$address','$city','IN  ','$zip_code','$email','$web_url','$mon_hours',
'
$tue_hours','$wed_hours','$thu_hours','$fri_hours  ','$sat_hours','$sun_hours',
'
$location','$desc','$info','$photo','$plan_agreem  ent','$list_plan','N','0','$account','$confirm_que  stion','$confirm_answer','0','0','0')";
$result=mysql_query($query); 
Reply With Quote