PHP - Changeable Array List, Via A File?
I'm working on a file uploading project, and I want to let admins restrict the files uploaded to certain files only. Should this be saved in the database, or should I make a file that saves an array?
If I do it via the file method, how would I update an array, say allowed.php? Example: How could I change <?php $allowed = array('zip', 'png'); ?> To <?php $allowed = array('gif', 'png'); ?> Similar TutorialsHere is how I get categories for article listing. Article can be written in several categories at once. So I have this code: Code: [Select] $category = '1,5,23,46'; //Category IDs $get_cats = explode("," , $category); $cats = ""; for ($i = 0; $i<count($get_cats); $i++ ) { $cat = trim($get_cats[$i]); $catSlug = get_value_of($cat, "inc/cat_ids.php"); $catName = str_replace("-"," ",$catSlug); $cats .= "<a href=\"index.php?category=$catSlug\">".strtoupper($catName)."</a>, "; } $cats = substr($cats,0,-2); As you can see there's get_value_of function that is used to read the category from the file. File is cat_ids.php and looks like this: Quote 1='category-name-1'; 2='category-name-2'; 3='category name-3'; 4='category-name-4'; 5='category-name-5'; etc. I want to improve this in order not to read the file at each step ("for" loop). Means, one can load the file and then generate a list of (links) category compared to the numbers (Ids). So if $category is "1,3,4" I want to get list like this (by reading cat_ids.php): category-name-1, category name-3, category-name-4 With current function I read value for every ID from file in every step. So if article have 10 or more categories script load file 10 or more times. Looking for a solution to do this from a reading file only once. Thanks. Hello! Hi, In my mysql database i have a text input option, in the registration form and edit my details form i have a multiple select dropdown list, which user selects options to populate the text input box, which ultimately populates the text field in the mysql database. All works perfectly. The dropdownlist consists of 3 parts <optgroups> first is current selection (what is the usesr current selection)works fine, The second <optgroup> is existing words, what words we(the site) have given as options, and the third <optgroup> is the words that others have used. This is where im having a small problem. Because its a text field when i call the data from the database, it calls the entire text box as a single option in my select list.. I want to break the words in the text field (at the comma) and have them listed each one as an option in the select list. Example what i need: Words in text box:(my input allows the "comma") word1, word2, word3, word4, word5, word6, How i want them called/displayed: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> here's my code: $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $original_functionsexperience =doSelectSql($query,1); $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $functionsexperiencelist=doSelectSql($query); $funcexpList ="<select multiple=\"multiple\" onchange=\"setFunctionsexperience(this.options)\">"; foreach ($functionsexperiencelist as $functionsexperienceal) { $selected=""; if ($functionsexperienceals->allwords == $original_functionsexperience) $selected=' selected="selected"'; $allwords=$functionsexperienceal->allwords; $funcexpList .= "<optgroup label=\"Current selection\"> <option value=\"".$allwords."\" ".$selected." >".$allwords."</option> </optgroup> <optgroup label=\"Existing Words\"> <option value=\"existing1,\">existing1</option> <option value=\"existing2,\">existing2</option> <option value=\"existing3,\">existing3</option> <option value=\"existing4,\">existing4</option> <option value=\"existing5,\">existing5</option> <option value=\"existing6,\">existing6</option> </optgroup> <optgroup label=\"Others added\"> //heres problem <option value=\"".$allwordsgeneral."\">".$allwordsgeneral."</option> </optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; The result im getting for optgroup others added: word1, word2, word3, word4, word5, how can i get it like this: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> Hi, I use the following code to create a select menu from an array of options stored in LISTS.php: include 'LISTS.php'; print('<select id="from" name="from">'); foreach ($langList as $lang) {printf('<option %s>%s</option>', ($from1 == $lang ? 'selected="selected"' : ''), $lang); } echo '</select>'; where LISTS.php includes the following: $langList = array(' ','English', 'French', 'German', 'Dutch', 'Spanish'); This works great, but now I want to do something similar with a checkbox list, where each checkbox has an associated 'onchange' javascript function and I'm getting pretty stuck. My checkbox list is of the following form: Code: [Select] <html> <ul style="height: 95px; overflow: auto; width: 200px; border: 1px solid #480091; list-style-type: none; margin: 0; padding: 0;"> <li id="li1b"><label for="chk1b"><input name="chk1b" id="chk1b" type="checkbox" onchange="function1('chk1b','li1b')">Option1</label></li> <li id="li2b"><label for="chk2b"><input name="chk2b" id="chk2b" type="checkbox" onchange="function1('chk2b','li2b')">Option2</label></li> //etc. </ul> </html> What I want to do is have 'Option1', 'Option2', etc. stored in an array in LISTS.php and have a PHP script that populates the checkbox list accordingly, in a similar manner to my select menu above. I can't work out how to get the ID of the next <li> and the next <input> in the list to go up by one each time, e.g. 'li1b' then 'li2b', 'li3b', etc. Could someone pls help me out? Thanks! Been looking on the web on and off for the past few days but can't seem to find a list of all file types that PHP (or is it Apache) appreciates. Like when you go and upload file using a form and then it outputs: Quote Array ( [upload_file] => Array ( [name] => discount_xcart_orders.csv [type] => text/comma-separated-values [tmp_name] => /tmp/phprAk2R6 [error] => 0 [size] => 674 ) ) Is there an entire list of file types that this '[type] => text/comma-separated-values' falls under? Just out of interest of course, Jeremy. Right now I am displaying a list of files in a dir. the files do not output in any type of order I would like them to display either alphabetically or by upload date. I have posted my code below any help would be great. <table border=0><tr><td align=center><b>File</b></td><td><b>Remove</b></td></tr> <?php $remove = $_GET[remove]; $dir = "/home/public_html/upload/files/"; $remove = $dir."".$remove; if($remove != "/home/public_html/upload/files/") {unlink($remove);} // Open a known directory, and proceed to read its contents if (is_dir($dir)) { if ($dh = opendir($dir)) { $color = "gray"; while (($file = readdir($dh)) !== false) { if($color == "gray") { $color = "black"; } elseif($color == "black") { $color = "gray"; } if(filetype($dir . $file) == "file") { echo "<tr bgcolor=$color><td><a href='../upload/files/$file'>$file</a></td><td align=center><a href='?remove=$file'>X</a></td></tr>"; } } closedir($dh); } } ?> </table> Hello. I am just trying to sort an array alphabetically. Here's the code I'm using: function GetAssocCharities($registrationNo) { $db = ConnectionString::ConnectTo_www_ago_mo_gov_data(); $sqlstring = "SELECT * FROM charityPartners where RegistrationNo LIKE '$registrationNo' ORDER BY Name"; $results = @mysql_query($sqlstring); $org = null; while ($resultArray = mysql_fetch_array($results)) { $temp = new Registrants($resultArray['ARegNoFormatted'], $resultArray); $org[] = $temp; } return asort($org); } When I try to loop through the array using a foreach loop, I get an error that Invalid argument supplied for foreach(). Here's my foreach loop: $lstCharities = OrgQueries::GetAssocCharities($registrant->RegNoFormatted); foreach($lstCharities as $c) { //dom something here } I'm sure its something with not understanding list v array or something or that nature, but I'm not having much luck figuring it out with google. Thanks! Alright, so I have an xml file differences.xml that is being parsed in XML. This is what the xml looks like: <item code="lM" name="dog"> <cost>5000</cost> <Start>12/15/2010</Start> <End>01/13/2011</End> </item> <item code="lF" name="cat"> <cost>5000</cost> <Start>04/15/2010</Start> <End>04/23/2011</End> </item>[/ I want to have the item names (dog, cat) show in a dropdown menu so that I can select these items for editing before storing in my mysql database. This is the php code I have so far: <?PHP $xml = simplexml_load_file("differences.xml"); $object = $xml->xpath("//item"); echo '<SELECT name=object>'; foreach ($object['name'] as $key => $value) { echo '<OPTION value='.$value.'> '.$value; } echo '</select>'; ?> I do have a dropdown list but there are no values inside it (it is empty). Can anyone help me figure out why? I do have this code that does work which lists the items in plaintext (not in a dropdown) so hopefull this will help us out: <?PHP $xml = simplexml_load_file("differences.xml"); $object = $xml->xpath("//item"); $count = count($object); $i = 0; while($i < $count) { echo '<h1>'.$object[$i]['name'].'</h1>'; $i++; } ?> nothing gets put into the select list I would like to go from a glob list, which is working great, to a download link kinda thing. So, The glob list is shown and each file has a link. The problem is that the download folder for PHP is apparently NOT within my website, but in another portion of the server. Also that when I modify the code to work within the website, it doesnt work. Probably because of the glob array. Anyone have an idea on how to fix this? Code: Code: [Select] <?php $dir = "/downloads/"; $files = glob($dir."*.zip", GLOB_NOSORT); // echo'<select name="Files">'; foreach($files as $file){ // echo'<option value="'.$file.'">'.basename($file).'</option>'; echo '<p><a href="/downloads/'.basename($file).'">'.basename($file).'</a></p>'; }; // echo'</select>'; ?> I am passing an array to an option list but if a value has two words, the second word doesnt get sent via POST. So if the value should be THE ONE, the word ONE doesnt get sent via POST. Kinda wierd, wondered if there is an easy explanation for this? Code: [Select] <?php echo '<SELECT name=carrier>'; foreach ($allcar as $key => $value) { echo '<OPTION value=' . $value . '> ' . $value . ''; } echo '</select>'; ?> Hello, I'm having trouble getting a piece of code to work and as a result right now i have bloated code on a simple task. Currently my code looks like this: Code: [Select] //convert responses into one string to check for spam $full_string = $name.' | '.$email.' | '.$message; //look for spam words if ( (stristr($full_string, 'test')) || (stristr($full_string, 'http')) || (stristr($full_string, 'www')) || (stristr($full_string, 'site')) || (stristr($full_string, 'fake')) || (stristr($full_string, 'viagra')) || (stristr($full_string, 'cialis')) || (stristr($full_string, 'asdf')) || (stristr($full_string, 'txt')) || (stristr($full_string, 'doc')) || (stristr($full_string, 'xls')) || (stristr($full_string, 'htm')) || (stristr($full_string, 'sale')) || (stristr($full_string, 'free')) ){ I would like to instead place all my 'spam' words in an array like this Code: [Select] $spam_array = array('test', 'viagra', cialis...etc If i had all my spam words in an array, how would i write an if statement to check if any of those words appeared in $full_string ? Thanks for your help! Hello again: I would like to see if someone can either show me some code, or point me in the direction of a good article about uploading a file (meaning a photo, .JPG, .GIF, etc) via PHP. I have only done this with ASP. My searches on GOOGLE are only showing me ways to upload a file INTO the database, and I don't believe that is the proper way to do it. I have always stored the file (.JPG) in a folder called "uploads" and stored the file name (myPhoto.JPG) in the database. So, if I want to make a Team bio list with a photo, a title, and a description what is the proper way to do that? Meaning, I click "Add Player" and a form with title, description, and a photo upload field appear. The data is filled out, "Submit" is clicked, and the photo is uploaded to "uploads" and all other data is inserted into the database. I had wanted to be able to modify, delete, or make inactive each player, and use a dropdown SELECT menu to choose what player to edit. Any ideas how to accomplish this? I would appreciate the help! I am using the following php script to display all the files that are uploaded in a directory on a page. There are two files in the folder I do not want displayed: .htaccess & index.php. Can someone help me out and provide a little guidance about what I need to do to print all the file names EXCEPT for those two. I imagine some sort of if statement. CODE: Top of page: Code: [Select] <?php $dirname = "."; $dir = opendir($dirname); ?> Body: Code: [Select] <?php while(false != ($file = readdir($dir))) { if(($file != ".") and ($file != "..")) { echo("<a href='$dirname$file'>$file</a> <br />"); } } ?> Thanks so much! I am getting following notice in code: Notice: Undefined offset: 2 in ... Notice: Undefined offset: 3 in etc.. I want to get all files from directory with pagination system. It is working, but how to remove this notice (when error_reportings is enabled). Here is code: $exts = array('w3g'); $per_page = 10; // How many files per page $files = array(); $dir = opendir($replayLocation); while( ($file = readdir($dir)) != false ) { if( !is_dir($file) && !in_array($file,array('.','..')) && in_array(substr($file,strrpos($file,'.')+1),$exts) ) { $files[] = array( 'path' => $file, 'filename' => pathinfo($file,PATHINFO_BASENAME), 'name' => pathinfo($file,PATHINFO_FILENAME) ); } } closedir($dir); $file_count = count($files); $page_count = ceil( $file_count / $per_page ); $page = ( isset($_GET['page']) && is_numeric($_GET['page']) ) ? (int) $_GET['page'] : 1; if( $page > $page_count ) { $page = $page_count; } if( $page < 1 ) { $page = 1; } $offset = ( ( $page - 1 ) * $per_page ); for( $i = $offset; $i < ( $offset + $per_page ); $i++ ) { //$files[$i]['path']; //$files[$i]['filename']; if (file_exists($replayLocation."/".$files[$i]['filename'])) { $current_file = $files[$i]['filename']; echo "<a href='./$replayLocation/$current_file'>$current_file</a><br>"; } } echo '<br><table><tr><td style="padding-right:24px;" align="right" class="pagination">'; if( $page > 1 ) { echo ' <a href="./file.php?page=1"><<</a> <a href="./file.php?page=',( $page - 1 ),'"><</a> '; } $range = 5; for( $x = ($page - $range); $x < ( ($page + $range) + 1); $x++ ) { if( $x > 0 && $x <= $page_count ) { if( $x == $page ) { echo ' [ ',$x,' ] '; } else { echo ' <a href="./file.php?page=',$x,'">',$x,'</a> '; } } } if( $page != $page_count ) { echo ' <a href="./file.php?page=',( $page + 1 ),'">></a> <a href="./file.php?page=',$page_count,'">>></a> '; } echo '</td></tr></table>'; Code: [Select] $arr = array('../', 'j/', 'AcidBB/', 'fileBOMB/', 'OurHome', 'up'); foreach ($arr as $value) { // echo "Value: $value<br /><br />"; if (is_dir($value)) { echo "<tr> <td>{$value}</td> <td><font color='#66FF33'>Exists</font></td></tr><br />"; } else { echo "<tr> <td>{$value}</td> <td><font color='#FF0000'>Does Not Exist</font></td></tr><br />"; } } ~~~ Solved after posting. Sorry. ~~~ Ok i have an Array of directories i need to check before the script installs itself, I know how to check for directories but i dont know how to scan each array in the list without calling each one seperately in Code: [Select] If() { } Else If { } Else If { } And so on and so on... My Question is, If a For Statement is neaded, How would i go about checking each string in the Array List? Hi pals, I got a complex Array from the Query. it's Structure is like Quote Array ( => Array ( [server_name] => anes.admod.net [id] => 1 [server_id] => 1 [description] => nice Anes Server [status] => 0 [max_down_count] => 9 [check_interval] => 15 [fail_recheck] => 6 [log_retain] => 1 [warning] => 12 [critical] => 15 [timeout] => 8 [audible] => Y [email] => Y [im] => Y [sms] => Y [rss] => N [rssid] => [vcare] => Y [created] => 2010-12-06 10:26:26 [last_update] => 2010-12-13 16:41:48 [name] => POP3 [port] => 110 [okay] => OK [warn] => WARNING [crit] => CRITICAL [down] => Connection refused [advanced] => N [typestatus] => 1 ) [1] => Array ( [server_name] => neseema.admod.net [id] => 2 [server_id] => 2 [description] => another server [status] => 1 [max_down_count] => 11 [check_interval] => 15 [fail_recheck] => 12 [log_retain] => 2 [warning] => 12 [critical] => 16 [timeout] => 6 [audible] => Y [email] => Y [im] => Y [sms] => N [rss] => N [rssid] => [vcare] => N [created] => 2010-12-07 10:27:42 [last_update] => 2010-12-13 16:41:48 [name] => Cpanel [port] => 2082 [okay] => OK [warn] => WARNING [crit] => CRITICAL [down] => Connection refused [advanced] => N [typestatus] => 1 ) [2] => Array ( [server_name] => anes.admod.net [id] => 3 [server_id] => 1 [description] => nice Anes Server another Service [status] => 1 [max_down_count] => 14 [check_interval] => 15 [fail_recheck] => 3 [log_retain] => 3 [warning] => 12 [critical] => 16 [timeout] => 18 [audible] => Y [email] => [im] => [sms] => [rss] => N [rssid] => [vcare] => N [created] => 2010-12-07 12:58:01 [last_update] => 2010-12-13 16:41:48 [name] => SMTP [port] => 25 [okay] => OK [warn] => WARNING [crit] => CRITICAL [down] => Connection refused [advanced] => N [typestatus] => 1 ) ) In this Result I have 2 Rows in result to show, I mean I need to merge the data of First (0th) and Third(2nd) element because it display the data of same item. So How it can done, I am working in that whole day but not get a solution fully.... I saw a near solution like : <?php $input = array( 0 => array ( 'id' => 160, 'payment_period' => 'Monthly', 'plan_payment_type_id' => 171, 'payment_type_id' => 4), 1 => Array ( 'id' => 160, 'payment_period' => 'Monthly', 'plan_payment_type_id' => 172, 'payment_type_id' => 5), 2 => Array ( 'id' => 161, 'payment_period' => 'Weekly', 'plan_payment_type_id' => 173, 'payment_type_id' => 9), ); echo "<pre>"; print_r($input); echo "</pre>"; echo "****************************************************************************"; $output = array(); $id_array = array(); $i = 0; foreach($input as $key=>$val) { if(array_key_exists($val['id'],$id_array)) { $pos = $id_array[$val['id']]; $output[$pos]['payment_types'][] = array('plan_payment_type_id'=> $val['plan_payment_type_id'],'payment_type_id' => $val['payment_type_id']); } else { $output[$i] = array('id' => $val['id'],'payment_period' => $val['payment_period'],'payment_types' => array(array('plan_payment_type_id'=> $val['plan_payment_type_id'],'payment_type_id' => $val['payment_type_id']))); $id_array[$val['id']] = $i; $i++; } } echo "<pre>"; print_r($output); echo "</pre>"; ?> But I cannot handle it nicely, please give any sample or helping code idea for same , waiting your immediate Reply Thankfully Anes P.A Hi all! Ok I am trying to put a delimited list like so , EX. item qty, item name, item price | item qty, item name, item price | item qty, item name, item price | etc. into an array so I can access it like this - $product[0] = qty, $product[1] = name, etc. My code just isnt working. This is what I have so far. $prod = array(); //breaking products text down for display $products1 = explode("|", $products); $num_prod1 = count($products1); $count = 0; foreach($products1 as $p) { $prod[] = $p; $products2 = explode(",", $p); foreach($products2 as $p2) { $prod[$count] = $prod[$count][$p2]; } $count++; } |