Jump to content

bad_gui

Members
  • Posts

    36
  • Joined

  • Last visited

Everything posted by bad_gui

  1. Very nice. Thank you. I swapped in your cleaned up function and now the page lists all albums and song titles For example it lists: http://guruplug/NMT-Cloudplayer/index.php?path=.%2Fmusic%2FElvis+Costello+%26+The+Attractions I can see links for albums and music files but now the HTML5 player embeded on the page won't play and shows an error message: In this section of code I point $_ENV['basepath'] to the symlink that points to the folder with the mp3 files 14 // The base path of the files you wish to browse 15 $_ENV['basepath'] = './music'; 16 // File extension you want to hide from the list 17 $_ENV['hidden_files'] = array ("\\/", "php", "css", "htaccess", "sub", "srt", "idx", "smi", "js", "DS_Store", "jpg", "gif", "nmj", "jsp", "txt"); 18 // File name of album cover art 19 $_ENV['coverart'] = 'cover.jpg'; 20 // File name of album review text 21 $_ENV['review'] = 'review.txt'; If I use anything else but ./music there is no listing of music filenames. However, now the html5 player seems to want a . in front of the %2F seperator. 135 <body> 136 <?php 137 setlocale(LC_ALL, 'en_US.UTF8'); 138 139 if (isset($_GET['path'])){ 140 $actpath = $_GET['path']; 141 } else { 142 $actpath = $_ENV['basepath']; 143 } 144 ?> 145 <div data-role="page"> 146 <div data-role="header"> 147 <!--Breadcrumb --> 148 <div id="breadcrumb"> 149 <?php 150 if ( $actpath != $_ENV['basepath']){ 151 $crumb = explode("/",str_replace($_ENV['basepath'],"",$actpath)); 152 echo "<span><a href='" .$_SERVER['PHP_SELF']."?path=".$_ENV['basepath']."'>Home</a></span>"; 153 $newpath = ''; 154 foreach($crumb as $index => $value) { 155 $newpath .= $value; 156 // is not last item // 157 if($index < count($crumb)-1) 158 echo "<a href='" .$_SERVER['PHP_SELF']."?path=".$_ENV['basepath']. $newpath ."'>$value</a>"; 159 // it is last item // 160 else 161 echo $value; 162 $newpath .= '/'; 163 }} 164 ?> 165 </div>
  2. My first project is to get it to list all of the music files and directories. Right now I am stuck trying to substitute is_file with some construct that will display all the files. I know that $file handles the filenames correctly because I can echo them. I can probably switch to urlencode as you suggest but I believe that won't fix my immediate challenge.
  3. I am trying to modify the code from this source http://www.networkedmediatank.com/showthread.php?tid=54009 to play my mp3 files remotely. Some albums and mp3 filenames contain special characters. I would like to learn how to fix the code rather than simply rename my files. I made some changes to replace the special characters with the hex codes. The problem is that the function uses is_file and is_dir to display the filenames and directories but these return false for names with special characters. What logical test can I use to distinguish files and directories to display all of the contents correctly? Or do I use this http://php.net/manual/en/class.normalizer.php to allow is_file to work on special characters? function showContent($path){ if ($handle = opendir($path)){ while (false !== ($file = readdir($handle))) { if ($file=='.' || $file=='..' || valid_extension($file)) { // echo "hidden<br>"; } else { $old = array(" ", "'", "&", ":" ); $new = array("%20","%27","%26","%3A"); $fName = htmlspecialchars($file, ENT_HTML401); $file = $path."/".$file; $file = htmlspecialchars($file, ENT_HTML401); $fileurl = str_replace($old, $new, $file); if(is_file($file)) { echo "<li class='music' data-icon='false'><a class='musicfile' href='#' data-src='".$_ENV['domain'].$fileurl."'><h3>".$fName."</h3>" ."<p class='size ui-li-aside'> ".format_size(filesize($file))."</p></a></li>"; } elseif (is_dir($file)) { echo "<li class='folder'><a href='".$_SERVER['SCRIPT_NAME']."?path=".$file."'>"; if (file_exists($file."/".$_ENV['coverart'])) { $folderart = $_ENV['domain'].$fileurl."/".$_ENV['coverart']; echo "<img src='$folderart'>"; } else { echo "<img src='images/jewelcase_empty.png'>"; }; echo "<h3>$fName</h3></a></li>"; } } } closedir($handle); } }
  4. Sysadmin at work won't change httpd.conf default charset from iso-8859 but I found a site with useful workaround that solves most of the problem http://www.phpwact.org/php/i18n/charsets So I added the follwing code to the top of index.php and now IE switches to utf-8 when the encoding is set to "auto" This will display the characters correctly on the main page but not when other pages are used. // Setting the Content-Type header with charset header('Content-Type: text/html; charset=utf-8'); However, since I am a newbie to php and html I can't figure out how to apply this to all of the code since some pages still display garbled characters But when I do a "view source" in the browser it gives Do I add the php code to set the header to utf-8 to every php script?
  5. I have a journal article DB project that I coded at home. The database character set is UTF-8 since some author names are foreign. I switched my browser's default font to utf-8. The php code includes <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> <TITLE>Virtual Library</TITLE> <STYLE TYPE="text/css"> Everything works great at home. When I installed this at work for general use, I found internet exploder doesn't allow a permanent change to the default character encoding. It also ignores the code above even when I set the encoding to "autodetect" Even if I manually set utf-8, every time I browse away the default is reset to Western (ISO-8859-1 I think). So now the old entries I transfered by mysqldump are mangled when viewing with Western, but the new entries are mangled when viewing with utf-8. I can change all to latin1 but this doesn't cover all French, Spanish Swedish etc. characters, no? I tried searching the web but couldn't find how professional developers (I'm an amateur) deal with the accented character in a mixed browser environment. Several options are listed in this link but which is http://en.wikipedia.org/wiki/Help:Special_characters
  6. Thanks for the code but as a newbie I still don't understand why both versions use an associative array for a scalar result, namely the total number of records. Here is my limited understanding: $query = "SELECT COUNT(*) FROM library"; $result = @mysql_query ($query); The code above will have the number of records in the string $result $rows = @mysql_fetch_assoc($result); $articles = $rows['num']; Now the string $rows will be an array which contains the number of entries and $articles is set to the associative array element 'num' This code works but why have the extra complexity- or is there something I am missing?
  7. I'm modifying an open source project and trying to get a listing of the total number of entries in a mysql DB. $query = "SELECT COUNT(*) FROM library"; $result = @mysql_query ($query); $rows = @mysql_fetch_row ($result); $articles = $rows[0]; $where = "overall"; @mysql_close($link); print "<BR><BR>$articles articles $where<BR><BR>"; I don't understand why mysql_fetch_row is used since it gives the next available number as a scalar not an array. I tried simply setting $articles = @mysql_query ($query); but no value is printed. I get the correct result if I paste the command SELECT COUNT(*) FROM library into phpmyadmin's sql window. Postscript. When I removed the error suppression "@" the verbose errors revealed that no DB connection was established and what was missing was the following code to connect to the DB before executing the query $link = @mysql_connect($database_host, $database_user, $database_password); @mysql_select_db ($database_name); However I still don't understand why it doesn't just use the result from SELECT COUNT(*) FROM library??
  8. I am a php amateur and have been working on a journal article DB that has the descriptive info in the DB and the associated article is on the local file system as a pdf. The user can search for and read the article in their browser. Some pdf files can be quite large with images etc. I was wondering if it is worth storing them compressed with gzip and using the php zlib compression functions to store the article in a gzipped form and gunzip it when the user requests to view it. Users can upload new pdf files or download ones they don't have. This is an application to be used internally at a tiny company. Our servers aren't bad but they are not cutting edge either. Sorry don't have specs. Compression of a sample pdf reduced its size by 15%. The trade-off is extra CPU load and my code modifying effort to save on server disk space and I/O? Anyone have any experience with this?
  9. Thanks! That solved the problem. I've been using the Welling & Thompson book but there is so much more to php (like nested $_GET etc).
  10. Sorry, I'm just learning. I tried print " <A HREF=\"index.php?action=browse&select=$_GET[select]&browseby=$_GET[browseby]&$_GET[browseby]=urlencode($paper[0])&show=brief&orderby=$_GET[browseby]\"> $paper[0]</A> ($paper[1])<BR>"; But this gives I also tried single quotes around the 'urlencode($paper[0])' but that didn't work either. What am I missing?
  11. I added an echo statement to see if my guess was right echo $_GET{$_GET['browseby']} This produces a text string that is truncated from the & character onwards Any ideas?
  12. I'm modifying someone else code. It's a journal article DB that grabs descriptive info from a public database and inserts it into a mysql DB and associates the pdf file with the entry. I can upload a paper from the journal Protein engineering, design & selection without a problem. I can see the entry using the php scripts "search" and "browse" functions EXCEPT for one which is "browse by journal" I can see the journal name listed but when I click it says "no hits" I'm learning php so I'd appreciate it if someone could point me in the right direction. Basically when the user sees a list of journals produced by scanning the DB a producing a list of all unique entries in the journal column, the user can click on the journal name and get a list of all the articles from that journal. When I click on the journal name I get this link in the browser: http://192.168.1.99/librarian/index.php?action=browse&select=all&browseby=journal&journal=Protein engineering, design & selection&show=brief&orderby=journal Here is the relevant code (I think) to produce the listing of journals: print " <A HREF=\"index.php?action=browse&select=$_GET[select]&browseby=$_GET[browseby]&$_GET[browseby]=$paper[0]&show=brief&orderby=$_GET[browseby]\"> $paper[0]</A> ($paper[1])<BR>"; Here is the code (I think) that actually scans the DB if (!empty($_GET["browseby"])) { $browseby_string="WHERE $_GET[browseby]='".$_GET{$_GET['browseby']}."'"; if ($_GET[browseby] == 'category') $browseby_string="WHERE category REGEXP '(^|[|])".$_GET{$_GET['browseby']}."([|]|$)'"; $chain = "$_GET[browseby]=".$_GET{$_GET["browseby"]}."&"; } else { $browseby_string=''; $chain = ''; } if (substr($_GET["select"], -4) == '.pdf') { $query = "SELECT * FROM library WHERE file='$_GET[select]'"; } else { $query = "SELECT * FROM library $browseby_string ORDER BY $orderby_string $ordering LIMIT $from,20"; } $result = @mysql_query ($query); $rows = @mysql_num_rows($result); @mysql_close($link); So is the problem is that $browseby_string="WHERE $_GET[browseby]='".$_GET{$_GET['browseby']}."'"; can't recognize the string Protein engineering, design & selection Do I just mysql_escape_string this?
  13. Yes. When I looked at the man page I saw that it would remove (for example) the last 7 characters after the @ symbol. What I couldn't see is how it would replace all of the text after special characters regardless of how long the string is (for example 7, 9 23 characters long). Thanks to all you php pros for awesome fixes.
  14. my apologies. I am looking for a general tool that will remove the extra text after special characters such as : and ( in any string. Sed is an old-school unix/linux tool http://en.wikipedia.org/wiki/Sed Thanks uniflare! Your script works. I looked at the man pages for preg_match but didn't see how it would work for this purpose.
  15. I couldn't figure out how to use regexp to delete text after and including certain characters. For example, I want to convert the following text to simply this for uploading into my database The problem is that there are many journal titles with extra text after the relevant title and I don't want to write rules to substitute specific strings for each and every case. Here is a sed script that trims the text from the colon to the end. I can add a version of the sed command also for open parenthesis and dash etc. sed -i -e 's/:.*/ /' bogus.txt How would I apply this when the input text is coming from $_POST? $title = str_replace("\r\n", " ", $_POST["title"]);
  16. I'm modifying someone else's code. One problem is that when the app queries a public database some non-standard entries cause problems. For example the journal name: Science (New York, N.Y.) should be just Science Here is the code that strips HTML but how do I strip text after the open parenthesis? if (strstr($result_array[$i], "<Title>")) { $journal = utf8_decode(trim(strip_tags($result_array[$i]))); } Does this require regexp?
  17. yes, I want the text that is the value uploaded into mysql
  18. I'm trying to allow the user to use checkboxes to insert default category terms into the category column of a flatfile DB. There is more code but I'm only showing what is relevant. None of my php books uses checkboxes in this way and I can't figure out how to get this to work. $category = $_GET[category]; <TD VALIGN="top"> Check appropriate category: </TD> <TD> <?php echo $_GET["category"] ?> <LABEL> downstream signaling <INPUT TYPE="checkbox" NAME="category[]" VALUE="downstream signaling"> </LABEL> <LABEL> surface protein <INPUT TYPE="checkbox" NAME="category[]" VALUE="surface protein"> </LABEL> <LABEL> autocrine signaling <INPUT TYPE="checkbox" NAME="category[]" VALUE="autocrine signaling"> </LABEL> </TD> <TR> <TD VALIGN="top"> <INPUT TYPE="submit" VALUE="Upload"> <INPUT TYPE="reset" VALUE=" Reset "> </TD> </TR></TABLE> </FORM>
  19. Short answer: how much work do I want to put into this? Currently data is written to a flatfile but what happens when user tries to search 1,000 rows? Does this take miliseconds or a minute or two. If the user tries to search the abstract field which will contain a paragraph of text for each row, this is a lot of work but this field can't be split into another table. The only columns that make sense to convert to their own tables are journal, date1 and category. Since I'm a novice and I'm modifying someone else's code this could be a lot of effort. Adding a column to the existing flatfile is easy but will I regret it when there are 1,000 rows to search?
  20. Since I'm modifying someone else's code, the parsing stuff is there I just need to convert checkbox selections to text in a "category" column inserted into the existing flatfile. The flatfile looks like this: file_id int(11) file tinytext authors text title text I journal tinytext date1 smallint(5) date2 date abstract text The only columns that seem worth converting to their own tables are journal and date1 (year of publication). All of the others will have mostly unique data. I would need to rework lots of code.
  21. I'm new to php and mysql. I am modifying a project to maintain journal articles in a searchable database. The original project had a flat file structure and one of the columns was "category" which contained the arbitrary keywords the authors provided. In order to make things more consistent I switched to checkboxes for the user to select which fixed categories to associate with the paper. My question is: for a db of about 1,000 rows, should I keep the flat file (easier for me to code) or add a table of 8 categories and papers can be assigned to multiple categories (difficult for me to code). I would like to give users the option of browsing a category. Would this be slow with a flat file?
  22. O.K. so now when I change the starting <? to <?php the index.php script is ignored and the browser loads another one, intsall.php, from the same directory Why? While poking around my php.ini file I found this. Where can I read more about code differences between php4 and php5 since my book covers php5?
  23. I am trying to learn php with the Welling & Thompson book. I am updating and customizing a package that will search an archive of documents on my hard drive- no remote access. This works with php4 but when I upgraded my distro it came with php5.2 and now the index.php has problems. The first problem is an echo statement that has the second quote escaped (by the percent?). I haven't found why php5 treats this code differently than php4. I would like to make the code work for both versions. <? session_start(); include 'data.php'; $reload_to_install = str_replace("index", "install", $_SERVER['PHP_SELF']); if (!isset($database_host)) header("Location: http://$_SERVER[HTTP_HOST]$reload_to_install"); if (!isset($_GET["from"])) { $from = '0'; } else { $from = $_GET["from"]; } if (!empty($_SESSION["user"])) $username = explode ('@', strtoupper($_SESSION["user"])); /////////////start define functions////////////////////// function show_results($result,$select,$from,$show) { include 'data.php'; $i = $from; $link = mysql_connect($database_host, $database_user, $database_password); mysql_select_db ($database_name); echo ' <TABLE BORDER="0" CELLPADDING="5" CELLSPACING="5" WIDTH="100%">'; while ($paper = mysql_fetch_array($result)){ $i = $i + 1; Here is what I see in my browser:
  24. I'm modifying an abandoned project for a database to store journal articles. The original model was a flat file with certain features (such as a browse all option) that suggests it was never designed to get very big. Since this will be used at my company, there may eventually be 10,000 entries? The pdf files are written to a directory and the database schema looks like this: mysql> describe library; +----------+----------------------+------+-----+------------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+----------------------+------+-----+------------+----------------+ | file_id | int(11) | | PRI | NULL | auto_increment | | file | tinytext | | MUL | | | | authors | text | | | | | | title | text | | | | | | journal | tinytext | | | | | | date1 | smallint(5) unsigned | | | 0 | | | date2 | date | | | 0000-00-00 | | | abstract | text | | | | | +----------+----------------------+------+-----+------------+----------------+ Is it worth splitting off a new table for journals and perhaps authors? There would be multiple articles from the same journal and I could code this easily. For the authors, it would take me a while to figure out how to split multiple authors into individual rows. Is the effort to normalize worth it? This is a MYISAM table to allow for text searching. My guess is that at most 5 users will be accessing it simultaneously. Most searches would consist of "title contains text ABC" or "abstract contains DEF." I'm trying to implement a table of categories so that users who upload can associate a paper with one or more categories. What about indexing the title, authors and abstract? Would this eliminate the need to normalize this database? I'm new to mysql and php and I've been reading a lot but this is a bit more complicated than the ordering database examples described in my books. I would appreciate any advice.
  25. Success! Thanks for your help. I'm using the Welling & Thompson PHP and MySQL Development book but there are some things that can only be answered on a forum. if (move_uploaded_file ($_FILES['filename']['tmp_name'], "$library_path$file")) { $query = "INSERT INTO library (file_id,file,authors,title,journal,date1,date2,abstract) VALUES (NULL,'$file','".mysql_real_escape_string($authors)."','$title','$journal','$_POST[date1]','$date2', '$abstract')"; $result = mysql_query ($query) OR die(mysql_error()); if (!$result) { die ("Could not upload into database: <br />" . mysql_error()); } $_POST["file"] = ""; $_POST["authors"] = ""; $_POST["title"] = ""; $_POST["journal"] = ""; $_POST["date1"] = ""; $_POST["date2"] = ""; $_POST["abstract"] = ""; print '<H3 STYLE="color: red">The article was recorded successfully.</H3>';
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.