PHP - Creating A Sitemap Directly From An Sql Database
Hello,
I have found the following code which creates a sitemap from the home directory of files. Please could you point me in the right direction for changing this so that it looks up from my sql database and for each name within the database creates an entry in the sitemap (e.g. www.mysite.com/[NAME]). Thanks for your help, Stu Code: [Select] <?php /******************************************************************************\ * Author : Binny V Abraham * * Website: http://www.bin-co.com/ * * E-Mail : binnyva at gmail * * Get more PHP scripts from http://www.bin-co.com/php/ * ****************************************************************************** * Name : PHP Google Search Sitemap Generator * * Version : 1.00.A * * Date : Friday 17 November 2006 * * Page : http://www.bin-co.com/php/programs/sitemap_generator/ * * * * You can use this script to create the sitemap for your site automatically. * * The script will recursively visit all files on your site and create a * * sitemap XML file in the format needed by Google. * * * * Get more PHP scripts from http://www.bin-co.com/php/ * \******************************************************************************/ // Please edit these values before running your script. //////////////////////////////////// Options //////////////////////////////////// $url = "http://www.WEBSITE_NAME.com/"; //The Url of the site - the last '/' is needed $root_dir = ''; //Where the root of the site is with relation to this file. $file_mask = '*.php'; //Or *.html or whatever - Any pattern that can be used in the glob() php function can be used here. //The file to which the result is written to - must be writable. The file name is relative from root. $sitemap_file = 'sitemap.xml'; // Stuff to be ignored... //Ignore the file/folder if these words appear in the name $always_ignore = array( 'local_common.php','images' ); //These files will not be linked in the sitemap. $ignore_files = array( '404.php','error.php','configuration.php','include.inc' ); //The script will not enter these folders $ignore_folders = array( 'Waste','php_uploads','images','includes','lib','js','css','styles','system','stats','CVS','.svn' ); //The default priority for all pages - the priority of all pages will increase/decrease with respect to this. $starting_priority = ($_REQUEST['starting_priority']) ? $_REQUEST['starting_priority'] : 70; /////////////////////////// Stop editing now - Configurations are over //////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// function generateSiteMap() { global $url, $file_mask, $root_dir, $sitemap_file, $starting_priority; global $always_ignore, $ignore_files, $ignore_folders; global $total_file_count,$average, $lowest_priority_page, $lowest_priority; /////////////////////////////////////// Code //////////////////////////////////// chdir($root_dir); $all_pages = getFiles(''); $xml_string = '<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"> <?php # '; $modified_priority = array(); for ($i=30;$i>0;$i--) array_push($modified_priority,$i); $lowest_priority = 100; $lowest_priority_page = ""; //Process the files foreach ($all_pages as $link) { //Find the modified time. $handle = fopen($link,'r'); $info = fstat($handle); fclose($handle); $modified_at = date('Y-m-d\Th:i:s\Z',$info['mtime']); $modified_before = ceil((time() - $info['mtime']) / (60 * 60 * 24)); $priority = $starting_priority; //Starting priority //If the file was modified recently, increase the importance if($modified_before < 30) { $priority += $modified_priority[$modified_before]; } if(preg_match('/index\.\w{3,4}$/',$link)) { $link = preg_replace('/index\.\w{3,4}$/',"",$link); $priority += 20; } //These priority detectors should be different for different sites :TODO: if(strpos($link,'example')) $priority -= 30; //If the page is an example page elseif(strpos($link,'demo')) $priority -= 30; if(strpos($link,'tuorial')) $priority += 10; if(strpos($link,'script')) $priority += 5; if(strpos($link,'other') !== false) $priority -= 20; //Priority based on depth $depth = substr_count($link,'/'); if($depth < 2) $priority += 10; // Yes, I know this is flawed. if($depth > 2) $priority += $depth * 5; // But the results are better. if($priority > 100) $priority = 100; $loc = $url . $link; if(substr($loc,-1,1) == '/') $loc = substr($loc,0,-1);//Remove the last '/' char. $total_priority += $priority; if($lowest_priority > $priority) { $lowest_priority = $priority;//Find the file with the lowest priority. $lowest_priority_page = $loc; } $priority = $priority / 100; //The priority is given in decimals $xml_string .= " <url> <loc>$loc</loc> <lastmod>$modified_at</lastmod> <priority>$priority</priority> </url>\n"; } $xml_string .= "</urlset>"; if(!$hndl = fopen($sitemap_file,'w')) { //header("Content-type:text/plain"); print "Can't open sitemap file - '$sitemap_file'.\nDumping result to screen...\n<br /><br /><br />\n\n\n"; print '<textarea rows="25" cols="70" style="width:100%">'.$xml_string.'</textarea>'; } else { print '<p>Sitemap was written to <a href="' . $url.$sitemap_file .'">'. $url.$sitemap_file .'></a></p>'; fputs($hndl,$xml_string); fclose($hndl); } $total_file_count = count($all_pages); $average = round(($total_priority/$total_file_count),2); } ///////////////////////////////////////// Functions ///////////////////////////////// // File finding function. function getFiles($cd) { $links = array(); $directory = ($cd) ? $cd . '/' : '';//Add the slash only if we are in a valid folder $files = glob($directory . $GLOBALS['file_mask']); foreach($files as $link) { //Use this only if it is NOT on our ignore lists if(in_array($link,$GLOBALS['ignore_files'])) continue; if(in_array(basename($link),$GLOBALS['always_ignore'])) continue; array_push($links, $link); } //asort($links);//Sort 'em - to get the index at top. //Get All folders. $folders = glob($directory . '*',GLOB_ONLYDIR);//GLOB_ONLYDIR not avalilabe on windows. foreach($folders as $dir) { //Use this only if it is NOT on our ignore lists $name = basename($dir); if(in_array($name,$GLOBALS['always_ignore'])) continue; if(in_array($dir,$GLOBALS['ignore_folders'])) continue; $more_pages = getFiles($dir); // :RECURSION: if(count($more_pages)) $links = array_merge($links,$more_pages);//We need all thing in 1 single dimentional array. } return $links; } //////////////////////////////// Display ///////////////////////////// ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.1 Transitional//EN"> <html> <head> <title>Sitemap Generation Using PHP</title> <style type="text/css"> a {color:blue;text-decoration:none;} a:hover {color:red;} </style> </head> <body> <h1>PHP Google Search Sitemap Generator Script</h1> <?php if($_POST['action'] == 'Create Sitemap') { generateSiteMap(); ?> <h2>Sitemap Created...</h2> <h2>Statastics</h2> <p><strong><?php echo $total_file_count; ?></strong> files were found and indexed.<br /> Lowest priority of <strong><?php echo $lowest_priority; ?></strong> was given to <a href='<?php echo $lowest_priority_page; ?>'><?php echo $lowest_priority_page; ?></a></p> Average Priority : <strong><?php echo $average; ?></strong><br /> <h2>Redo</h2> <?php } else { ?> <p>You can use this script to create the sitemap for your site automatically. The script will recursively visit all files on your site and create a sitemap XML file in the format needed by Google. </p> <p>You can customize the result by changing the starting priorities.</p> <h2>Set Starting Priority</h2> <?php } ?> <form action="create_sitemap.php" method="post"> Starting Priority : <input type="text" name="starting_priority" size="3" value="<?php echo $starting_priority; ?>" /> <input type="submit" name="action" value="Create Sitemap" /> </form> </body> </html> Similar TutorialsI wish to create a sitemap for a shopping cart and so far it seem this needs to be in XML format? is this true ? If so are there any templates that I can use to base my sitemap on. I have a array for example: Code: [Select] $item = array( "Great <em>Bittern</em>"=>"Botaurus stellaris", "Little <em>Grebe</em>"=>"Tachybaptus ruficollis", "Black-necked Grebe"=>"Podiceps nigricollis"); which will output Code: [Select] Array ( [Great Bittern] => Botaurus stellaris [Little Grebe] => Tachybaptus ruficollis [Black-necked Grebe] => Podiceps nigricollis ) how can I input data from a database so it comes out as the array assuming I have $row[3] and $row[0] as the data? for example Code: [Select] while($row=mysql_fetch_array($result)){ //$item.=array($row[3],$row[0]); //array_push($item,array($row[3]=>$row[0])); //$item.=array($row[3]=>$row[0]); $item.="[".$row[3]."]=>".$row[0]; } which of course doesnt work?? Hello, I've created a page search to return results from my database inventory. On top of these results I would like to display a seperate list of five products not included in the search results but share the same sub_category_b (a column in my SQL table). Posted below is my primary query of the database. If anyone can help me out with this it would be appreciated. Code: [Select] $colname_product = "-1"; if (isset($_GET['title'])) { $colname_product = $_GET['title']; } mysql_select_db($database_inventory, $inventory); $query_product = sprintf("SELECT * FROM inventory WHERE item_name LIKE %s OR item_desc LIKE %s ", GetSQLValueString("%" . $colname_product . "%", "text"),GetSQLValueString("%" . $colname_product . "%", "text")); $product = mysql_query($query_product, $inventory) or die(mysql_error()); $row_product = mysql_fetch_assoc($product); I've fooled around with this one for some time and haven't come up with a clear cut answer. Thank you in advance! Here is the sample page: http://hoosierhoopsreport.com/pg-test/ Trying to create a table that has three sections (groupings). That part I have figured out. The first grouping is sorted numerically. The second group is sorted alphabetically based on what part of the state they live in. It's breaking down this second part that I can't seem to get. (The third group is just what's left over, sorted alphabetically.) So it needs to look like this: (Each group and region have their own header row. Only Group 2 is broken down into Regions.) Group 1 Group 2 -Region 1 -Region 2 -Region 3 -Region 4 -Region 5 Group 3 The sample page above, in Group 2, it just shows Region 1 header. Code: [Select] $query = 'SELECT * FROM a_playerRank WHERE year="2015" and position="1" ORDER BY grouping DESC,rankPos,region,nameLast'; $results = mysql_query($query) or trigger_error('MySQL error: ' . mysql_error()); $currentGrouping = false; $currentRegion = false; while($line = mysql_fetch_assoc($results)) { if($currentGrouping != $line['grouping']) { //Status has changed, display status header $currentGrouping = $line['grouping']; if($line['grouping']==2) { echo '<thead> <tr> <th class="num">#</th> <th class="top">Top 10</th> <th class="height">HT</th>'; if (current_user_can("access_s2member_level4")){ echo '<th class="level">Level</th>'; } echo' <th class="school">City (School)</th>'; if (current_user_can("access_s2member_level4")){ echo '<th class="summer">Summer Team</th>'; } echo' <th class="college">College</th> </tr> </thead>'; } if($line['grouping']==1) {echo '<tr><th colspan="7">Best of the Rest</th></tr>'; if($currentRegion != $line['region']) { $currentRegion = $line['region']; echo '<tr><th colspan="7">Region' .$line['region'] . '</th></tr>';} } if($line['grouping']==0) echo '<tr><th colspan="7">Names to Know</th></tr>'; } Hi there I've been working with some code to display a single record on page. This all works fine and I'm able to pull what I want from the database. My problems is trying to use that data and turning it into something else like a link. I have a field in the database called image url which contains rows of image urls. So here is the problem area of the code: Code: [Select] <?php //////Displaying Data///////////// $id=$_GET['id']; // Collecting data from query string if(!is_numeric($id)){ // Checking data it is a number or not echo "Data Error"; exit; } $fetch=mysql_query("select * from productfeeds where ProductID=$id "); $row=mysql_fetch_object($fetch); echo mysql_error(); echo "<table>"; echo " <tr><td><b>ProductID</b></td><td>$row->ProductID</td></tr> <tr><td><b>ProductName</b></td><td>$row->ProductName</td></tr> <tr><td><b>ProductPrice</b></td><td>$row->ProductPrice</td></tr> //problem area for me <tr><td><b>Image</b></td><td>$row->ImageURL</td></tr> echo "</table>"; I'm trying to edit this part of the code: <tr><td><b>Image</b></td><td>$row->ImageURL</td></tr> I've tried this: <tr><td><b>Image</b></td><td><a href='{$row['URL']}'> <img src='{$row['ImageURL']}'></a> and <tr><td><b>Image</b></td><td><a href='$row['URL']'> <img src='$row['ImageURL']'></a> //removed brackets but I'm just getting errors. Can you guys help please? Thank you very much. I'm trying to create a website, that echo's out a bunch of groups, where each group contains a group of checkboxes, containing A value, and a label for the checkbox, the way it is created right now, is foreach that echo's out a bunch of php arrays, which was easier than the static way before - But still, it's static in some way, or not very user friendly at the moment.. My problem is that I really want to write it in a database when I have the option. Is there anyone that can give some tips how to do? At the moment, my foreach looks like this: Code: [Select] echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">'; /* NEXT WE CREATE OUR FOREACH LOOPS TO ECHO THE HTML FOR LOOKS AND CHECKBOXES */ $totalID=0; // this is a counter we use to build our check box names foreach ($items as $list){ $totalID++; // add one to the checkbox name counter echo "<h2>{$list['title']}</h2>\n"; // and echo out our section header foreach ($list['items'] as $cbox){ // now for each item in the list, call it $cbox // $cbox now holds the item name, and point value echo "<label class='checkbox'><input type='checkbox' name='totals[$totalID][]' value='{$cbox[1]}'> {$cbox[0]}</label>\n"; } } echo "</form>"; And my array is something like this: Code: [Select] $items['computers']['title']='Computer Brand'; $items['computers']['items'][]=array('Apple iMac',1); $items['computers']['items'][]=array('Apple Macbook',.5); $items['phones']['title']='Phone Brand'; $items['phones']['items'][]=array('iPhone',1); $items['phones']['items'][]=array('HTC',1); As said, I can write this, but takes time. I want to get it into a database, that data above, but I'm having problems about echo'ing it out, I really can't see how I should do. My current database looks like this: Thank you! Okay, I'll make this short and sweet, and all side comments are irrelevant. I'm doing this for my own happies So using Facebook.com's API you can extract all of a specific user's friends in an array. Well I'm making a array check to see who on that users friend list was removed or deleted them that week using array_dif(); in this method: 1) User allows the application 2) Application catches the user's friends_id's in an array and stores them // this is where i'm having trouble, i'll come back to it 3) User then waits a few days and notices their friend count is no longer 400, it's now 399! 4) User logs into my application, and checks the previously uploaded array against their current array of friends. Okay now to the part i'm struggling with is, what would you do? Should i store them each uniquely in a database? Because some users have 4,000+ friends and that gets quite strenuous. OR! Should i save them into a txt file unique to that person's user_id. I kind of like the 2nd option, however it's less ( to my newbish mind ) customizable versus the sql_queries. Once again, i'd like to reiterate, i don't care that this is again Facebooks terms of service, it's for my own personal gain and just enjoy taking on projects in my spare time that force my brain to work hard. That's all, hope you excuse the typos and poor grammar. Typed this pretty quickly, any questions - feel free to ask! Hi. I'm trying to create my first XML sitemap that I am going to be submitting to google. The sitemap is going to be PHP but using MOD rewrite to make it look like an XML file. The site map has been created. http://test.powtest.co.uk/sitemap.xml But, I now want to style it. However, when I add the XML style file, I get an error: Parse error: syntax error, unexpected T_STRING in /home/a/d/adele/web/public_html/sitemap.php on line 1 I'm not to sure how to get my PHP file to read in the XML style file. Any help would be much appreciated PHP sitemap (sitemap.xml) Code: [Select] <?xml-stylesheet type="text/xsl" href="sitemap.xsl"?> <?PHP require_once('includes/initialize.php'); $newAbout = Aboutme::find_by_id(1); $aboutDateMod = $newContact->dateMod; $newContact = Contact_details::find_by_id(1); $contactDateMod = $newContact->dateMod; $lastService = Services::find_last_posted(); $servicesDateMod = $lastService->dateMod; $lastBlog = Blog::find_last_posted(); $blogDateMod = $lastBlog->dateMod; // TOP NAVIGATION echo ' <url> <loc>'.SITE_DOMAIN.DS.'</loc> <lastmod>2011-01-17</lastmod> <changefreq>yearly</changefreq> <priority>0.8</priority> </url> <url> <loc>'.SITE_DOMAIN.DS.'services</loc> <lastmod>'.$servicesDateMod.'</lastmod> <changefreq>daily</changefreq> <priority>0.8</priority> </url> <url> <loc>'.SITE_DOMAIN.DS.'testimonials</loc> <lastmod>2011-01-17</lastmod> <changefreq>daily</changefreq> <priority>0.8</priority> </url> <url> <loc>'.SITE_DOMAIN.DS.'about_adele_fifer</loc> <lastmod>'.$aboutDateMod.'</lastmod> <changefreq>yearly</changefreq> <priority>0.8</priority> </url> <url> <loc>'.SITE_DOMAIN.DS.'contact</loc> <lastmod>'.$contactDateMod.'</lastmod> <changefreq>never</changefreq> <priority>0.8</priority> </url> <url> <loc>'.SITE_DOMAIN.DS.'tips</loc> <lastmod>'.$blogDateMod.'</lastmod> <changefreq>daily</changefreq> <priority>0.8</priority> </url>'; // SERVICE CAT $check = Services::count_CID(); if($check >= 1){ $serviceCat = Services_categories::find_all_order_by_exclude_nonFolder('category', 'ASC'); foreach($serviceCat as $serviceCats){ $ID = $serviceCats->id; $cat = ucwords($serviceCats->category); $servicesCatDateMod = $serviceCats->dateMod; if($checkCat = Services::if_CID_exists($ID)){ echo ' <url> <loc>'.make_cat_url('services_list', $ID, $cat).'</loc> <lastmod>'.$servicesCatDateMod.'</lastmod> <changefreq>daily</changefreq> <priority>0.8</priority> </url>'; } } } // SERVICE LIST $serviceCat = Services::find_all_order_by('title', 'ASC'); foreach($serviceCat as $serviceCats){ $ID = $serviceCats->id; $title = ucwords($serviceCats->title); $servicesDateMod = $serviceCats->dateMod; echo ' <url> <loc>'.make_url('services', $ID, $title).'</loc> <lastmod>'.$servicesDateMod.'</lastmod> <changefreq>yearly</changefreq> <priority>0.8</priority> </url>'; } // BLOG CAT $blogCat = Blog_categories::find_all_order_by('category', 'ASC'); foreach($blogCat as $blogCats){ $ID = $blogCats->id; $cat = ucwords($blogCats->category); $desc = $blogCats->smallDesc; $img = $blogCats->img; echo ' <url> <loc>'.make_cat_url('tips_list', $ID, $cat).'</loc> <lastmod>'.$servicesCatDateMod.'</lastmod> <changefreq>daily</changefreq> <priority>0.8</priority> </url>'; } // BLOG $blogCat = Blog::find_all_order_by('position', 'ASC'); foreach($blogCat as $blogCats){ $ID = $blogCats->id; $title = ucwords($blogCats->title); echo ' <url> <loc>'.make_url('tips', $ID, $title).'</loc> <lastmod>'.$servicesCatDateMod.'</lastmod> <changefreq>yearly</changefreq> <priority>0.8</priority> </url>'; } ?> XML Stylesheet (sitemap.xsl) Code: [Select] <?xml version="1.0" encoding="UTF-8"?><!-- DWXMLSource="http://test.powtest.co.uk/sitemap.xml" --> <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> <!ENTITY copy "©"> <!ENTITY reg "®"> <!ENTITY trade "™"> <!ENTITY mdash "—"> <!ENTITY ldquo "“"> <!ENTITY rdquo "”"> <!ENTITY pound "£"> <!ENTITY yen "¥"> <!ENTITY euro "€"> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/> <xsl:template match="/"> <html> − <head> − <title> Adele Fifer </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> − <style type="text/css"> body { font-family: Arial, sans-serif; font-size:13px; } #intro { background-color:#CFEBF7; border:1px #2580B2 solid; padding:5px 13px 5px 13px; margin:10px; margin-top:40px; } #intro p { line-height: 16.8667px; } td { font-size:11px; } th { text-align:left; padding-right:30px; font-size:11px; } tr.high { background-color:whitesmoke; } #footer { padding:2px; margin:10px; font-size:8pt; color:gray; } #footer a { color:gray; } a { color:black; } #content { padding: 30px; } img, img a { border:none; } </style> </head> − <body> <h1>Adele Fifer Sitemap</h1> − <div id="content"> − <table cellpadding="5"> − <tr style="border-bottom: 1px solid black;"> <th>URL</th> <th>Priority</th> <th>Change Frequency</th> <th>LastChange</th> </tr> <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/> <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/> − <xsl:for-each select="sitemap:urlset/sitemap:url"> − <tr> − <xsl:if test="position() mod 2 != 1"> <xsl:attribute name="class">high</xsl:attribute> </xsl:if> − <td> − <xsl:variable name="itemURL"> <xsl:value-of select="sitemap:loc"/> </xsl:variable> − <a href="{$itemURL}"> <xsl:value-of select="sitemap:loc"/> </a> </td> − <td> <xsl:value-of select="concat(sitemap:priority*100,'%')"/> </td> − <td> <xsl:value-of select="concat(translate(substring(sitemap:changefreq, 1, 1),concat($lower, $upper),concat($upper, $lower)),substring(sitemap:changefreq, 2))"/> </td> − <td> <xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/> </td> </tr> </xsl:for-each> </table> </div> − <div id="footer"> <a href="http://test.powtest.co.uk/about_adele_fifer">About Adele Fifer</a> </div> </body> </html> </xsl:template> </xsl:stylesheet> I'm wanting to make a sitemap for my website but should I includes ALL possible url's? For example I have a search page (where you can search a film) where the url syntax is something like "search.php?type=all&film=a+film". Should I make sure that all possible urls are included in my sitemap e.g all the films in my database? Hope that makes sense. Thanks for any help. Greetings, What I'm trying to do is have users upload their event information into a database which would include a flyer. I don't want the image file to go into the database (other than the filename) rather I'd like it to be dropped into a directory. In the same script I'd like to dynamically generate a thumbnail. I have the two scripts and separately they work fine, but I can't get them to work together. I'm guessing the conflict because the thumbnail script is using $_POST and the mysql script is using $_SESSION. If so how can I modify them to both use $_SESSION? The thumbnail script is goes from line 1 - 146 and the mysql portion is the rest. The results of processing this look something like this. QUERY TEXT: INSERT INTO td_events (eventgenre_sel, eventname, eventvenue, eventdate, eventgenre, eventprice, eventpromoter, eventflyer) VALUES ('12', 'spooky times', 'Ironwood Stage & Grill', '2010-12-17 22:36:00', 'DNB', '5000', 'me', '174366-1.jpg') <?php $debug = FALSE; /********************************************************************************************** CREATES THUMBNAIL **********************************************************************************************/ //define a maxim size for the uploaded images define ("MAX_SIZE","1024"); // define the width and height for the thumbnail // note that theese dimmensions are considered the maximum dimmension and are not fixed, // because we have to keep the image ratio intact or it will be deformed define ("WIDTH","500"); define ("HEIGHT","650"); // this is the function that will create the thumbnail image from the uploaded image // the resize will be done considering the width and height defined, but without deforming the image function make_thumb($img_name,$filename,$new_w,$new_h) { //get image extension. $ext=getExtension($img_name); //creates the new image using the appropriate function from gd library if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext) || !strcmp("JPG",$ext)) $src_img=imagecreatefromjpeg($img_name); if(!strcmp("png",$ext) || !strcmp("PNG",$ext)) $src_img=imagecreatefrompng($img_name); //gets the dimmensions of the image $old_x=imageSX($src_img); $old_y=imageSY($src_img); // next we will calculate the new dimmensions for the thumbnail image // the next steps will be taken: // 1. calculate the ratio by dividing the old dimmensions with the new ones // 2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable // and the height will be calculated so the image ratio will not change // 3. otherwise we will use the height ratio for the image // as a result, only one of the dimmensions will be from the fixed ones $ratio1=$old_x/$new_w; $ratio2=$old_y/$new_h; if($ratio1>$ratio2) { $thumb_w=$new_w; $thumb_h=$old_y/$ratio1; } else { $thumb_h=$new_h; $thumb_w=$old_x/$ratio2; } // we create a new image with the new dimmensions $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); // resize the big image to the new created one imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // output the created image to the file. Now we will have the thumbnail into the file named by $filename if(!strcmp("png",$ext)) imagepng($dst_img,$filename); else imagejpeg($dst_img,$filename); //destroys source and destination images. imagedestroy($dst_img); imagedestroy($src_img); } // This function reads the extension of the file. // It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } // This variable is used as a flag. The value is initialized with 0 (meaning no error found) // and it will be changed to 1 if an error occurs. If the error occurs the file will not be uploaded. $errors=0; // checks if the form has been submitted if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $image=$_FILES['eventflyer']['name']; // if it is not empty if ($image) { // get the original name of the file from the clients machine $filename = stripslashes($_FILES['eventflyer']['name']); // get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); // if it is not a known extension, we will suppose it is an error, print an error message // and will not upload the file, otherwise we continue if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "JPG") && ($extension != "PNG") && ($extension != "png")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { // get the size of the image in bytes // $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which // the uploaded file was stored on the server $size=getimagesize($_FILES['eventflyer']['tmp_name']); $sizekb=filesize($_FILES['eventflyer']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($sizekb > MAX_SIZE*500) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name=$filename; //the new name will be containing the full path where will be stored (images folder) $newname="flyers/".$image_name; $copied = copy($_FILES['eventflyer']['tmp_name'], $newname); //we verify if the image has been uploaded, and print error instead if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; } else { // the new thumbnail image will be placed in images/thumbs/ folder $thumb_name='flyers/thumb_'.$image_name; // call the function that will create the thumbnail. The function will get as parameters // the image name, the thumbnail name and the width and height desired for the thumbnail $thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT); }} }} //If no errors registred, print the success message and show the thumbnail image created if(isset($_POST['Submit']) && !$errors) { echo "<h1>Thumbnail created Successfully!</h1>"; echo '<img src="'.$thumb_name.'">'; } /************************************************************ Adjust the headers... ************************************************************/ header("Expires: Thu, 17 May 2001 10:17:17 GMT"); // Date in the past header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 /***************************************************************************** Check the session details. we will store all the post variables in session variables this will make it easier to work with the verification routines *****************************************************************************/ session_start(); if (!isset($_SESSION['SESSION'])) require_once( "../include/session_init.php"); $arVal = array(); require_once("../include/session_funcs1.php"); reset ($_POST); while (list ($key, $val) = each ($_POST)) { if ($val == "") $val = "NULL"; $arVals[$key] = (get_magic_quotes_gpc()) ? $val : addslashes($val); if ($val == "NULL") $_SESSION[$key] = NULL; else $_SESSION[$key] = $val; if ($debug) echo $key . " : " . $arVals[$key] . "<br>"; } /********************************************************************************************** Make sure session variables have been set and then check for required fields otherwise return to the registration form to fix the errors. **********************************************************************************************/ // check to see if these variables have been set... if ((!isset($_SESSION["eventname"])) || (!isset($_SESSION["eventvenue"])) || (!isset($_SESSION["eventdate"])) || (!isset($_SESSION["eventgenre"])) || (!isset($_SESSION["eventprice"])) || (!isset($_SESSION["eventpromoter"])) || (!isset($_SESSION["eventflyer"]))) { resendToForm("?flg=red"); } // form variables must have something in them... if ($_SESSION['eventname'] == "" || $_SESSION['eventvenue'] == "" || $_SESSION['eventdate'] == "" || $_SESSION['eventgenre'] == "" || $_SESSION['eventprice'] == "" || $_SESSION['eventpromoter'] == "" || $_SESSION['eventflyer'] == "") { resendToForm("?flg=red"); } /********************************************************************************************** Insert into the database... **********************************************************************************************/ $conn = mysql_connect($_SESSION['MYSQL_SERVER1'],$_SESSION['MYSQL_LOGIN1'],$_SESSION['MYSQL_PASS1']) or die ('Error connecting to mysql'); mysql_select_db($_SESSION['MYSQL_DB1']) or die("Unable to select database"); $eventgenre_sel = addslashes($_REQUEST['eventgenre_sel']); $eventname = addslashes($_REQUEST['eventname']); $eventvenue = addslashes($_REQUEST['eventvenue']); $eventdate = addslashes($_REQUEST['eventdate']); $eventgenre = addslashes($_REQUEST['eventgenre']); $eventprice = addslashes($_REQUEST['eventprice']); $eventpromoter = addslashes($_REQUEST['eventpromoter']); $eventflyer = addslashes($_REQUEST['eventflyer']); $sqlquery = "INSERT INTO td_events (eventgenre_sel, eventname, eventvenue, eventdate, eventgenre, eventprice, eventpromoter, eventflyer) " ."VALUES ('$eventgenre_sel', '$eventname', '$eventvenue', '$eventdate', '$eventgenre', '$eventprice', '$eventpromoter', '$eventflyer')"; echo 'QUERY TEXT:<br />'.$sqlquery; $result = MYSQL_QUERY($sqlquery); $insertid = mysql_insert_id(); /*** This following function will update session variables and resend to the form so the user can fix errors ***/ function resendToForm($flags) { reset ($_POST); // store variables in session... while (list ($key, $val) = each ($_POST)) { $_SESSION[$key] = $val; } // go back to the form... //echo $flags; header("Location: /user_registration.php".$flags); exit; } mysql_close($conn); ?> First of all I have no idea how to do this. But I know it can be done. A little help would be alot for me. Thank you in advance. So I want to go through a sitemap and visit each of the link on the sitemap and save the URL on to a database. Example: Quote HP 5550N A3 Colour Laser Printer Konica Minolta PagePro 1350W A4 Mono Laser Printer HP 9050dn A3 Mono Laser Printer HP 5550DTN A3 Colour Laser Printer HP 5550HDN A3 Colour Laser Printer HP 5550DN A3 Colour Laser Printer Lets say this was on the sitemap and it just continues with other product like this. I want to write a code where it will go to the first link and saves the product URL on to the database and continues to do the same until the last link. On my example it would be HP 5550DN A3 Colour Laser Printer. Any help??? Any ideas?? I am not asking someone to write the code for me.. Just need help and good direction I'm wanting to make a sitemap for my website but as it's quite big there are a lot of url's I need to include. I was wondering if anyone know's of a way this can be done using PHP. e.g. using PHP to generate a list of URL's. I had a think myself but wasn't sure how to do it. Thanks for any help. Hi, I have found a nice little script to write to the xml file for google, but it appears not to be updating the file. Could someone please let me know what might be wrong as this is the first time I've tried to do this. Code: [Select] $dom = new DomDocument('1.0', 'utf-8'); $dom->load('../sitemap.xml'); // if it's a string, $dom->load($xmlFile) if is a file // create the new node element $node = $dom->createElement('url'); // build node $node->appendChild($dom->createElement('loc', $title)); $node->appendChild($dom->createElement('lastmode', date(Y-m-d))); $node->appendChild($dom->createElement('changefreq', 'monthly')); $node->appendChild($dom->createElement('priority', '2')); // append the child node to the root $dom->documentElement->appendChild($node); // get the document as an XML string $xmlStr = $dom->save(); I was wondering if it was something to do with the [urlset] tag within the xml file I'm using? The xml file is just a standard google sitemap.xml Any help on this would be great Cheers Rob I have a simple php script that updates my sitemap automatically. However, when you click the link to the sitemap at www.bomstudies.com/sitemap-xml.php - the last mod date is showing 1969. The php script works for files that are not in sub folders. such as /talks or /commentary. I just need to know what snippet of code i should add, change, or delete to the sitemap php side of it to show the correct last mod date for my xml sitemap. I greatly appreciate your help.
Thanks -
Here is some of my code:
The Config Code: posted as config.php
<?php From my experience, using Google's sitemap generator to generate a sitemap is not that good. It creates page that you do not want to show up. I am wondering what the best method is for creating a sitemap of a website so that only certain pages of the website show up on Google?
For the last 2 months I have purchased software and utilized free software to attempt to create a sitemap fro my websites
www.negroartist.com
www.africanafrican.com
all of them fail and do not look at all links. i.e. look at a photo album with all the htm in the photo album.
Most of the windows based software do not work and often crash. I want it to index ALL of my site (except images, pdf etc)
Is there any php code, program etc. out there to help me through my dilemna that has instructions for configurabillity? I can also try anything that uses apache etc.
i am at my whits end with this. please help.
has anyone used bing sitemap plugin? how do you install this baby?
my links will total in the hundreds of thousands.
thanks :-)
Hi, I have some jQuery tabs. I would like to be able to link to them directly, but I can't work out how to do this. I have the following code: <div class="container-outer">How could I link directly to each of the tabs? Thanks! I hope someone can help me out with this. What I would like to do is import a text file dircetly to a text area. I can't seem to find any examples on this (Yes I did search Google). I know how to upload but I'm not interested in storing files on the server - but rather just importing them directly to a textarea. Can anyone point me in the right direction? I can upload: <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> I can read: $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') But I'm not interested in either of these as they are unnecessary steps (or are they?). Is there not a way to simply browse/import a text file directly to a textarea (or anywhere for that matter) without having to actually save the file to the server? Something like this: <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> //uploader.php if (isset($_POST['submit'])) { $content = $_POST['"grab the contents of the file"']; echo "<textarea>"; echo $content; echo "</textarea>"; } Hi, im using colorbox(basically like lightbox) for some links on my site. When a user clicks the link it opens this lightbox. But if they type the link into the address bar manually it takes them to the actual page(which isnt formatted properly). Is there a way to open up the lightbox when they enter the address manually? or a work around? I'm trying to figure out a way to post data directly to a URL. For example: <?php if (isset($_POST["pass"]) && ($_POST["pass"]=="$password")) { echo "You did it"; ?> <?php } else { echo "<form method=\"post\"><p align=\"left\">"; echo "<input name=\"pass\" type=\"text\" size=\"25\" maxlength=\"40\"><input value=\"Enter Pass\" type=\"submit\"></form>"; exit; } ?> Let's assume $password is 'password'. Why can't I simply pass the information through the URL to access the page with something like this: Code: [Select] http://mypage.com/the-same-page.php?pass=password |