SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2008
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generate_Sef_Url

    I have a form for adding websites to a DB (part of code below) Currently, the code is able to look for an image in a folder titled /media/ and if the image exists it previews it. Is it possible to have the code look for an image file name in the folder /media/ and if the file name exists to automatically generate_sef_url ? Right now it only previews the image and I have to manually save the form for the ser_url to be created. It would be great if there was a function that can automatically accomplish this.




    HTML Code:
    					<tr>
    						<td class="form_title" >Icon</td>
    						<td><input type="file" name="fleIcon" />
    							<img src="images/icons/help.png" onclick="showHelp(this)" style="cursor:pointer" />
    							<div class="div_help"> The Image of the store to be displayed to visitor. </div>
    							
    							<?php
    								$file_name = "../media/".$form_data["WebsiteID"].".jpg" ;
    								if ( file_exists ( $file_name ) )
    									echo "<br><img src='$file_name' />" ;
    							?>
    						</td>
    					</tr>


    PHP Code:
    <?php
        
        session_start 
    ( ) ;
        require ( 
    "inc.login_check.php" ) ;
        require_once ( 
    "inc.admin_data.php" ) ;
        if ( 
    intval $_SESSION["admin_rights"]["r_website"] ) == )
        {
            
    header "location:home.php" ) ;
            exit();
        }

    include_once( 
    "../classes/misc.func.php" );
        
        
    $form_data = array ( ) ;
        
        if ( 
    intval $_GET["id"] ) > )
        {
            
    $dataArray $data->select "Website" "*" , array ( "WebsiteID" => intval $_GET["id"] ) ) ) ;
            
    $form_data $dataArray[0] ;
        }
        
        
        
        if ( 
    $_POST )
        {
            
    $postArray $_POST ;
            
            if ( 
    intval $postArray["WebsiteID"] > ) )
            {
                
    $dataValues = array ( ) ;
                foreach ( 
    $postArray as $field => $value )
                {
                    if ( 
    strchr $field "_Setting_" ) )
                    {
                        
    $fName str_replace "_Setting_" "" $field ) ;
                        
    $dataValues[$fName] = str_replace ("'","",stripslashes($value)) ;
                    }
                }
                
    $dataValues["IsActive"] = ;
                
    $data->update "Website" $dataValues , array ( "WebsiteID" => $postArray["WebsiteID"] ) ) ;
                
    re_generate_sef_url $postArray["WebsiteTitle_Setting_"] , $postArray["WebsiteID"] , "Website" ) ;
                if ( 
    $_FILES["fleIcon"]["name"] != "" )
                {
                    
    exec "chmod ../media/ 777" ) ;
                    
    move_uploaded_file $_FILES["fleIcon"]["tmp_name"] , "../media/".$postArray["WebsiteID"].".jpg" ) ;
                    
    exec "chmod ../media/ 755" ) ;
                }
                
    $data->delete "Website_Tag" , array ( "WebsiteID" => $postArray["WebsiteID"] ) , 300 ) ;
                if ( ! empty ( 
    $_POST["chkTag"] ) )
                        foreach ( 
    $_POST["chkTag"] as $tag )
                            
    $data->insert "Website_Tag" , array ( "WebsiteID" => $_POST["WebsiteID"], "TagID" => $tag ) ) ;
                
    $data->delete "Website_Offers" , array ( "WebsiteID" => $postArray["WebsiteID"] ) , 50 ) ;
                if ( ! empty ( 
    $_POST["EF_Title"] ) )
                {
                    
    exec "chmod ../media/ 777" ) ;
                    foreach ( 
    $_POST["EF_Title"] as $key => $val )
                    {
                        if ( 
    $val != "" )
                        {
                            
    $araay_to = array ( 
                                                    
    "WebsiteID" => $postArray["WebsiteID"],
                                                    
    "OfferTitle" => $val,
                                                    
    "Description" => $_POST["EF_Description"][$key],
                                                    
    "LandingPage" => $_POST["EF_URL"][$key],
                                                    
    "Image" => $_FILES["EF_Image"]["name"][$key],
                                                ) ;
                            if ( 
    $_FILES["EF_Image"]["name"][$key] != "" )
                            {
                                
                                
    move_uploaded_file$_FILES["EF_Image"]["tmp_name"][$key] , "../media/".$_FILES["EF_Image"]["name"][$key] ) ;
                            }
                            
    $data->insert "Website_Offers" $araay_to ) ;
                        }
                    }
                    
    exec "chmod ../media/ 755" ) ;
                }
                
    $_SESSION["str_system_message"] = "Website modified successfully." ;
                
    header "location:weblisting.php" ) ;
                exit ( ) ;
            }
            else
            {
                
                
    $dataValues = array ( ) ;
                
                foreach ( 
    $postArray as $field => $value )
                {
                    if ( 
    strchr $field "_Setting_" ) && $value != "" )
                    {
                        
    $fName str_replace "_Setting_" "" $field ) ;
                        
    $dataValues[$fName] = str_replace ("'","",stripslashes($value)) ;
                    }
                }
                
    $dataValues["IsActive"] = ;
                
    $website_prev $data->select "Website" "*" , array ( "WebsiteTitle" => $dataValues["WebsiteTitle"] ) ) ;
                if ( empty ( 
    $website_prev ) )
                {
                    
    $id $data->insert "Website" $dataValues ) ;
                    if ( 
    intval $id ) > )
                    {
                        
    generate_sef_url $_POST["WebsiteTitle_Setting_"] , $id "Website" ) ;
                        
                        if ( ! empty ( 
    $_POST["chkTag"] ) )
                            foreach ( 
    $_POST["chkTag"] as $tag )
                                
    $data->insert "Website_Tag" , array ( "WebsiteID" => $id"TagID" => $tag ) ) ;
                        
                        if ( 
    $_FILES["fleIcon"]["name"] != "" )
                        {
                            
    exec "chmod ../media/ 777" ) ;
                            
    move_uploaded_file $_FILES["fleIcon"]["tmp_name"] , "../media/".$id.".jpg" ) ;
                            
    exec "chmod ../media/ 755" ) ;
                        }
                        else
                        {
                            
    $img imagecreatefromjpeg "http://open.thumbshots.org/image.aspx?url=".$dataValues["AffilateURL"] ) ;
                            
    exec "chmod ../media/ 777" ) ;
                            
    imagejpeg$img "../media/".$id.".jpg" ) ;
                            
    imagedestroy $img ) ;
                            
    exec "chmod ../media/ 755" ) ;
                        }
                        if ( ! empty ( 
    $_POST["EF_Title"] ) )
                        {
                            
    exec "chmod ../media/ 777" ) ;
                            foreach ( 
    $_POST["EF_Title"] as $key => $val )
                            {
                                if ( 
    $val != "" )
                                {
                                    
    $araay_to = array ( 
                                                            
    "WebsiteID" => $id,
                                                            
    "OfferTitle" => $val,
                                                            
    "Description" => $_POST["EF_Description"][$key],
                                                            
    "LandingPage" => $_POST["EF_URL"][$key],
                                                            
    "Image" => $_FILES["EF_Image"]["name"][$key],
                                                        ) ;
                                    if ( 
    $_FILES["EF_Image"]["name"][$key] != "" )
                                    {
                                        
    move_uploaded_file$_FILES["EF_Image"]["tmp_name"][$key] , "../media/".$_FILES["EF_Image"]["name"][$key] ) ;
                                    }
                                    
    $data->insert "Website_Offers" $araay_to ) ;
                                }
                            }
                            
    exec "chmod ../media/ 755" ) ;
                        }
                        
    $_SESSION["str_system_message"] = "Website added successfully." ;
                    }
                    else
                    {
                        
    $form_data $dataValues ;
                        
    $_SESSION["str_system_message"] = "Website title already exists." ;
                    }
                }
                
                
    header "location:weblisting.php" ) ;
                exit ( ) ;
            }
            
        }
        
        
        
    $siteSettings null ;
        
    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2008
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no takers?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •