[Solved] Need help linking 2k files into html [closed]


Given your specific situation as explained in the chat,

  • you have no access to the ‘back end’
  • you DO have access and permission to change the directory-structure and file-names of the course-materials (pdf-files)
  • current path & filenaming conventions are a mess (don’t exist) and unpredictable
  • there is currently nothing linking course-codes with course-descriptions/course-materials
  • every course has 20 course-materials (pdf-files):
    • 5 study sheets
    • 5 study sheet answers
    • 5 graded assignments
    • 5 grades assignment answers

Alas, somewhere something has to be done (especially for future lazy maintainability).
Before things grow further out of hand I’d suggest to start by implementing a file-path/file-naming convention. This should also help assist in creating future other solutions then the one I’m suggesting to start with.

The main point (and current flaw) is the lack of any automatable relations/predictability!

First restructure your file-paths/file-names:
let’s make a folder we shall consider as root for the course-materials: courses/.

Inside course we create your main categories:

courses/math/        
courses/english/        
courses/science/       
courses/social science/       
courses/electives/        

Now for every course-category (eg: course/math/, course/english, etc.), you create folders (or copy the existing folders) and (re-)name them to the course-number:

courses/math/HS-ES-103/
courses/math/HS-ES-104/
etc...
courses/english/HS-ES-113/ 
courses/english/HS-ES-114/ 
etc...

Now, in every course (e.g. courses/math/HS-ES-103, courses/english/HS-ES-113) you create (or rename respectively) 4 folders:

courses/category/course-number/ssu/
courses/category/course-number/ssa/
courses/category/course-number/gau/
courses/category/course-number/gaa/ 

to contain the course-materials (pdf-files).
These should hold the course’s respective pdf-files.
Also, in every course (next to the 4 folders) you create a file containing the course’s meta-data:

  • Course Title (like: ‘ENGLISH 9 Common Core Semester 2’)
  • Grade Level
  • Course Materials
  • Course Description

This could be in xml, json, csv, txt… what ever you find simplest to parse from php.
Note: there is an added bonus to this as some simple description (preferably highly human readable) inside that folder-structure never hurts in the future…

Now, creating courses/category by hand is going to be faster then creating a script to do it.
The most of the work will be in creating (and moving relevant course-files) or renaming the course-code folders and adding the meta-data-info-file.

Finally the filenames must be alphabetically sortable in the correct order.
unpredictable_string_1.pdf is fine. two_unpredictable_string.pdf is not.

If there are folders that have unpredictable_string_[one|two|three|four|five].pdf you could clear them up using a commandline-script that replaces one, two, three, four and five with their respective numbers (1,2,3,4,5) in the filenames unpredictable_string_[1|2|3|4|5].pdf.

From here on it is easy to go one of two ways:

  • Rename the (sorted) file-names into predictable strings (so you don’t need to pass them to your html/json/php etc (you can once again do that using a simple command-line script).
  • Don’t rename the unpredictable file-names and make your directory-parsing script read out the actual file-names (I wouldn’t recommend this).

EXAMPLE final structure:

> dir courses/math/HS-ES-103/
courses/math/HS-ES-103/ssu/
courses/math/HS-ES-103/ssa/
courses/math/HS-ES-103/gau/
courses/math/HS-ES-103/gaa/ 
courses/math/HS-ES-103/info.txt  (json/csv/xml etc.) 

> dir courses/math/HS-ES-103/ssu
courses/math/HS-ES-103/ssu/HS-ES-103_ssu_1.pdf
courses/math/HS-ES-103/ssu/HS-ES-103_ssu_2.pdf
courses/math/HS-ES-103/ssu/HS-ES-103_ssu_3.pdf
courses/math/HS-ES-103/ssu/HS-ES-103_ssu_4.pdf
courses/math/HS-ES-103/ssu/HS-ES-103_ssu_5.pdf

Now that you have fixed your directory-structure it is a relative breeze to parse out any information and relations using for example PHP.

Now you could use PHP to build static pages dynamically from a template or have it create one (or one per category) json-files (or xml, csv, etc..) to pass to the browser..

It is important to note that it is NOT the idea to parse your whole directory-tree upon each and every page-request.
It would be better to have a hidden admin-page containing a function to auto-update the stored cache after an update. Alternatively you could auto-update once every 24 hours (using a common template loop that checks the cache-page/file’s time-stamp and if older then x amount of time, reruns the updater script).

Search SO for examples of parsing directories, files(csv/json etc) and caching a page.

Good luck with your project!

solved Need help linking 2k files into html [closed]