Sunday, 15 January 2012

How to use readdir in php - Interpretting someone elses code -


For the lack of a better word, I am reverse programming someone else's program to replace any part of the code Efficient Block of So far, I have fundamental programming in PHP, so some of the things I have not come before. Include the following;

  $ handle = opendir ("/ directory / k / video / files /"); // real directory $ filename = readdir ($ handle);   

In my understanding readdir () only gives the first file in that directory, although the rest of the PHP code is set as if it goes through all the files < P>

Update 1 - Requested by DCOder

here is the entire code (except for the addition) if the request is made in the form of a request) . The general purpose of the program is to upload video information in a video, to check if the video information is not already present, each file will need to be seen in the directory, but it only looks to one in my understanding.

  & lt; Html & gt; & Lt; Body & gt; & Lt ;? Opens the directory with symbolic links for php // video files (automatically populated) $ handle = opendir ("/ home / rgood / www / hpa2013fall /"); $ Filename = readdir ($ handle); If ($ handle) {while (wrong! == ($ filename = readdir ($ handle))} {if ($ filename [0] == "v" & strlen ($ filename) == 25) / / Retrieve date and time information variable by file name $ month = $ filename [7] $ filename [8] $ filename [9]; $ Day = $ filename [10] $ file name [11]; $ Hour = $ filename [13] $ file name [14]; $ Min = $ filename [16] $ file name [17]; $ Sec = $ filename [19] $ filename [20]; / * A bazillion if the file that you access to set the statements is the part that I am replacing with a database that I have created and can be easily populated using an excel vba script and it is mysql * / If ($ month == "February" & amp; $ day == "4") {$ title = "Title1"; $ Description = "Description1";} elseif // ... // // // Other {$ title = "no title"; $ Description = "no details.";} // Open database connection mysql_connect ("server", "user", "password"); // Select the appropriate connection settings / databases in the actual code mysql_select_db ("Database_Name"); // the proper name in the code // it checks mysql whether the file name already exists in the database $ ifquery = "SELECT * FROM table WHERE filename = '$ filename'"; $ Ifresults = mysql_query ($ ifquery); $ Rows = array (); // This loop results out if the same filename is found, then it puts $ rows [] while {$ row = mysql_fetch_array ($ ifresults)} {$ rows] = $ line; } // if (empty ($ rows)) {// it is a readable form of date / time and a compressed description is $ date = $ month, adds an additional entry '' $ Day '2013'; $ Time = $ hours ':'. $ Min ':'. $ Second; // Time-Edek will be a decimal representation of date / time / this is not an easily readable format, but it is easily used by the / mysql $ timedec = "1" sorting function. $ Monthdays $ day $ hours $ min $ second; To insert the file into the table, enter the // SQL code $ sql = "table (file name, title, date, description, time, timetable) values ​​('$ filename', '$ title', '$ date' , '$ Description', '$ time', '$ timeshack') "; Mysql_query ($ sql) or die (mysql_error ()); }}} Closed ($ handle); }? & Gt; & Lt; / Body & gt; & Lt; / Html & gt;    

Each call receives one file for readdir.

By inserting a little while (), you can read the entire folder.

No comments:

Post a Comment