rickarro Posted April 28, 2009 Share Posted April 28, 2009 I'm new to php and am just getting my feet wet, I would like to be able to look into a server folder and see all the pdf documents in it, and store links to those documents in a mysql database. Then access those files from a php script. I've read that it can be done but I've been unable to find out how. Is there anyone that can point me in the right direction? The purpose is to scan documents into a folder then be able to search or query those documents through php and open if necessary. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/155930-help-with-script/ Share on other sites More sharing options...
nankoweap Posted April 28, 2009 Share Posted April 28, 2009 this may be a good start... http://www.php.net/manual/en/refs.fileprocess.file.php jason Quote Link to comment https://forums.phpfreaks.com/topic/155930-help-with-script/#findComment-820817 Share on other sites More sharing options...
rickarro Posted April 28, 2009 Author Share Posted April 28, 2009 Thank you for the reply. Most of it looks a little over my head, for now, but very useful. Can we start out a little simpler. I know I need to create a form that will input to my mysql database, that I think I can do, I get a little confused as to how to get the form to put a link to the pdf file in the database, and also how to get php to see a fold on a server. I know, I know, new guys suck But we have to start somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/155930-help-with-script/#findComment-820830 Share on other sites More sharing options...
mikesta707 Posted April 28, 2009 Share Posted April 28, 2009 well, you could just have an input form, and have the user (you in this case I assume) input the url of the document (Probably has to be the absolute url IE http://www.mysite.com/pdfs/mypdf.pdf) and store that value into a database (after you sanitize the input of course) then once you want to make a link, you can access the database, get the URL (I assume you know how to do this, if not, i can explain in a later post) and output something like echo "<a href=\"$url\">Link text</a>"; $url is obviously the url that you got from the database. hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/155930-help-with-script/#findComment-820877 Share on other sites More sharing options...
radi8 Posted April 28, 2009 Share Posted April 28, 2009 I am copying this from the user contributed portion of the php documentation site (http://www.php.net/manual/en/ref.dir.php). This is NOT my code, but it appears to fit your situation. It will be an easy process to modify the second function to do the inserts to your db. This will NOT be 100% what you need, although it will get you close. I would suggest that you go to the link defined above and read through the comments and user comments/samples. They are a wealth of information and will get you on the right path. Also, check out the dir() functionality and comments. Good stuff there. I would like to present these two simple functions for generating a complete directory listing - as I feel the other examples are to restrictive in terms of usage. <?php function dirTree($dir) { $d = dir($dir); while (false !== ($entry = $d->read())) { if($entry != '.' && $entry != '..' && is_dir($dir.$entry)) $arDir[$entry] = dirTree($dir.$entry.'/'); } $d->close(); return $arDir; } function printTree($array, $level=0) { foreach($array as $key => $value) { echo "<div class='dir' style='width: ".($level*20)."px;'> </div>".$key."<br/>\n"; if(is_array($value)) printTree($value, $level+1); } } //Usage is as simple as this: $dir = "<any directory you like>"; $arDirTree = dirTree($dir); printTree($arDirTree); ?> It is easy to add files to the tree also - so enjoy. Quote Link to comment https://forums.phpfreaks.com/topic/155930-help-with-script/#findComment-821071 Share on other sites More sharing options...
rickarro Posted April 28, 2009 Author Share Posted April 28, 2009 Yes, this is very useful. I will be having someone else doing the input so I won't have total control and need to make it as simple and easy to use as possible. I can handle the input form but would prefer to have only the pdf document name inputted by the user instead of the whole url. Is it possible to have the http://www.mysite.com/pdfs/ portion be added by default so the user only has to add the actual name of the document? This would help greatly. I think i can also set up a simple search script that will be able to search through the urls in mysql to look for a particular file or files, then have it display the findings using the echo "<a href=\$url\">Link Text</a>";. This should work well. I'm assuming I would need to have it walk through an array to find the files that I want and then to display them all as individual links, so where the above echo shows $url, it would need to be the $resultofthearray? Is my thinking correct here? I think this because each of the findings will have its own link location (name of file), so will the href show link to each individual file? I'll keep reading on this as radi8 has suggested, but this is a great start. I appreciate the help. Quote Link to comment https://forums.phpfreaks.com/topic/155930-help-with-script/#findComment-821094 Share on other sites More sharing options...
rickarro Posted April 28, 2009 Author Share Posted April 28, 2009 I should also add that the number of files will be growing on a daily basis. This is like an archive file system so as time goes on, it will get bigger and bigger, but never smaller. Quote Link to comment https://forums.phpfreaks.com/topic/155930-help-with-script/#findComment-821097 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.