1st when a user signsup how can I check their name with a list of bad words? Like if a user tries to signup with the name "yousuck" I want to run that username against a list of badwords and if the bad word is anywhere in the username I want the form to fail. I know how to change the badwords but I'm not sure how to check within a word for a bad word. 2nd I bought a site a while back and it has a ton of user pictures on it. Atleast 500,000 pictures. I want to clean up the server a bit but I'm not sure how to do this. Okay I need to make a script that will go through each folder (every username has their own folder...I know stupid way to do it but I didn't code it) and compare the pictures in the folder to that in the database. If the picture isn't in the database I want to delete the picture. I have no clue how to go about doing this one so if anyone has any ideas I'm all ears. Thanks
I think this can be help full to you <?php // The "i" after the pattern delimiter indicates a case-insensitive search if (preg_match("/php/i", "PHP is the web scripting language of choice.")) { echo "A match was found."; } else { echo "A match was not found."; } ?> PHP:
Split the words in an array, then loop through it. Pseudo code: foreach $bad_array as $badword{ if(strpos($username, $badword) { echo 'try another name punk!'; break; } } PHP: 2. Best to loop through the database and do an if file_exists on each. Tick them all off and remove the left-overs.
Thanks this part made me laugh "try another name punk!". The only bad thing about doing the if file_exists is it will only clean up the pics that are in the database. There are a ton of pictures that are in the folders that don't have a entry in the database. The old owner had it setup so when the user deleted their picture it just removed the entry from the database but left the picture. So now I'm stuck with thousands of stranded pictures.
Make a file get contentds or c_url scritp and open a new folder. write a small script which will copy the pictures from pictures folder by the name of DB. It is so easy. than you can delete old pictures folder and rename new folder. No more problem. <? //we used C_URL for working better this is so fast and secure. mysql_connect("localhost", "root", "xxxxxx") or die ("Mistake"); mysql_select_db("DB") or die ("Mistake X"); $q=mysql_query("Select * from pics"); while ($r = mysql_fetch_array($q)) { $url = http://www.xxx.com/$r['picsurl']; //or $url = $r['picsurl']; I dont know how is your DB $name = ['picsname']; $ch = curl_init("$url"); $fp = fopen("$name","a"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); ?> PHP: You have to put this file in to new folder. After you made this I think u develop your script.
Tops did the first one. The second one : what you actually wanna do is loop through all the files in the pictures directory and query the database for a picture by that name, if no result is found then physically delete the image from the disk. ( Might be worth going vice versa too). Something like : <?php define( "MYSQL_HOSTNAME", "localhost"); # MySQL Hostname define( "MYSQL_USERNAME", "root" ); # MySQL Username define( "MYSQL_PASSWORD", "WyeValley" ); # MySQL Password define( "MYSQL_DATABASE", "database" ); # MySQL Databae define( "IMAGES_TABLE", "images" ); # The name of the table with the image data in define( "IMAGES_NAME_ROW", "rowname" ); # The name of the row in the above table that holds image names if( !@mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD) ) : die("Cannot connect to mysql server @ " . MYSQL_HOSTNAME ); endif; if( !@mysql_select_db(MYSQL_DATABASE) ) : die("Cannot select mysql database named " . MYSQL_DATABASE ); endif; # Open dir for reading ..... if( !($handle = opendir(".") ) ) : die("Cannot read current directory"); endif; # Start reading the directory contents while (false !== ( $file = readdir($handle)) ) : # Check for a physical file if( $file != "." and $file != ".." ) : # Query database for filename $temp = @mysql_query("SELECT * FROM " . IMAGES_TABLE . " WHERE " . IMAGES_NAME_ROW . " = $file LIMIT 1"); # Check query for result if( mysql_num_rows($temp) != 1 ) : if(!unlink($file)) : die("Cannot delete $file, please chmod this dir and contents to 777"); endif; endif; endif; endwhile; closedir($handle); ?> PHP: Obviously I haven't tested that, but that sorta thing will be in order here I think ....