PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY number (Database web hosting)
PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY number and then builds the filename from its composite parts. A series can contain up to 999 files and still remain in the correct order. The full listing follows: function getNextFilename($dir, $prefix, $type) { // run some security checks on the arguments supplied if (!is_dir($dir)) return false; if (!preg_match(’/^[-._a-z0-9]+$/i’, $prefix)) return false; $permittedTypes = array(’txt’,'doc’,'pdf’,'jpg’,'jpeg’,'gif’,'png’); if (!in_array(strtolower($type), $permittedTypes)) return false; // if the checks are OK, get an array of the directory contents $existing = scandir($dir); // create a search pattern for files that match the prefix and type $pattern = ‘/^’.$prefix.’(d+).’.$type.’$/i’; $nums = array(); // loop through the directory // get the numbers from all files that match the pattern foreach ($existing as $file) { if (preg_match($pattern, $file, $m)) { $nums[] = intval($m[1]); } } // find the highest number and increase it by 1 // if no file yet created, assign it number 1 $next = $nums ? max($nums)+1 : 1; // calculate how many zeros to prefix the number with if ($next < 10) { $zeros = '00'; } elseif ($next < 100) { $zeros = '0'; } else { $zeros = '' ; } // return the next filename in the series return "{$prefix}{$zeros}{$next}.{$type}"; } As with the buildFileList() function, I have created an array of acceptable file types (highlighted in bold on line 5 in the preceding code). Although create_series.php is used to create a text file, you can incorporate this function in a file upload script. If you need to change the range of acceptable file types, amend the $permittedTypes array. The function should not need any other alteration. The PHP 4 version is identical except for the way it opens and inspects the directory. Opening remote data sources PHP can open publicly available files on other servers just as easily as on the same server. This is particularly useful for accessing XML files or news feeds. All that you need to do is
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.