Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Database on website for users to add PDF files and view all PDF's?

Options
  • 24-01-2014 6:06pm
    #1
    Registered Users Posts: 225 ✭✭


    Ok so I want a website where users can browse through a bunch of PDF files. I also want them to be able to add their own PDF files and for this addition to then become visible to other users that might visit the site.

    I understand that I probably need to use a database to achieve this. However mySQL seems to require a knowledge of PHP, something I don't have. Is there a better, relatively simple way to achieve this using javascript?

    I have also ran into a lot of talk about server side and client side programming and how it becomes important with databases. I amn't sure how I distinguish between the two, however. Say I have two js documents. How do I specify which is client side, which is server? I am using 000webhost.com.

    I realize the q is a bit of a mess but I appreciate any guidance anyone can give me here. On paper the task doesn't seem to difficult to achieve.


Comments

  • Registered Users Posts: 6,039 ✭✭✭Talisman


    Your chosen host has 4 options for the server side scripting: Perl, PHP, Python & Ruby on Rails. They do not offer Node.js (server side Javascript).

    If you are intending to use the free offering then PHP is your only option.

    If you are insisting on doing everything in Javascript you will need to find another service - my suggestion would be to use a service like AppFog. You could use Amazon S3 to store the PDF files.

    This might also prove helpful: https://github.com/mozilla/pdf.js

    Based upon your initial post I would imagine that no matter which platform you choose for your project, you are on a steep learning curve.


  • Registered Users Posts: 27,088 ✭✭✭✭GreeBo


    so you need a few "bits"

    - A UI to display files (assuming you want the user to view them on the site and not download them?)
    - A UI to upload files (multipart/form file upload, browser will do all the work)
    - A backend to receive the file
    - Somewhere to store the file

    HTML/JS will handle 1 & 2
    Filesystem will handle 4
    Depending on your hosting solution you have various options for 3, this is your app/serverside code that will do the heavy lifting.

    I would second the opinion that based on your OP this may well be beyond your *current* abilities/understanding.


  • Registered Users Posts: 225 ✭✭TheSetMiner


    Thanks for the replies lads. I realize this is probably beyond my current abilities but I am willing to learn. I do have a couple of questions that I'd appreciate if you could answer as they are probably fundamental to my progression.

    - When you say server-side coding, where do I go to code this? You mention that my hosting provider allows Perl, PHP, Python & Ruby on Rails. As it happens, I know quite a bit of Python too so I was glad to hear that! But the whole server side/cleint side is still unclear to me. I have no idea how you knew that my hosting provider allows those programming languages and even less of an idea as to where I would go on that site, to write the relevant code. Do I merely upload a Python file? How would the host know if this was client/server?

    - I notice nobody is recommending mySQL databases for this yet this hosting provider actually encourages I use it, is mySQL in anyway useful here?

    - in response to the last poster, I guess if a user had to download the file to view it, that would be ok too.

    And initially, to simplify this project, I may leave out the bit where users can add their own PDF's. Would this make it more achievable, do you think? Once I get my head around the storage and retrieval of data from a database, I think I can start to move on to more difficult tasks. I am determined to learn though


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    I'd start with the simplest approach you can.

    Create a very basic web page, nothing fancy, just a few lines of text maybe.
    Work out how to upload the web page to your web server.
    Upload it.
    Upload a PDF to your web server
    Add a link to the web page to the PDF.

    That should keep you going for a couple of hours. When you've got to the point where you have a web page with a link to the PDF (which you can click on to download the PDF) come back and post again.


  • Registered Users Posts: 225 ✭✭TheSetMiner


    Graham wrote: »
    I'd start with the simplest approach you can.

    Create a very basic web page, nothing fancy, just a few lines of text maybe.
    Work out how to upload the web page to your web server.
    Upload it.
    Upload a PDF to your web server
    Add a link to the web page to the PDF.

    That should keep you going for a couple of hours. When you've got to the point where you have a web page with a link to the PDF (which you can click on to download the PDF) come back and post again.

    Cheers. I'll get on that now!


  • Advertisement
  • Registered Users Posts: 225 ✭✭TheSetMiner


    Graham wrote: »
    I'd start with the simplest approach you can.

    Create a very basic web page, nothing fancy, just a few lines of text maybe.
    Work out how to upload the web page to your web server.
    Upload it.
    Upload a PDF to your web server
    Add a link to the web page to the PDF.

    That should keep you going for a couple of hours. When you've got to the point where you have a web page with a link to the PDF (which you can click on to download the PDF) come back and post again.

    Done! Managed to get a basic site which allows the user to download a PDF file.

    tester12345.comoj.com

    Where do you reckon I should go from here?


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    Good start, you were much faster than I anticipated.

    Now turn your html page into a php page.

    Use a php variable to store your filename

    Replace the filename in your link with the php variable so that when the page is loaded, it looks and works exactly like your current page.


  • Registered Users Posts: 225 ✭✭TheSetMiner


    Graham wrote: »
    Good start, you were much faster than I anticipated.

    Now turn your html page into a php page.

    Use a php variable to store your filename

    Replace the filename in your link with the php variable so that when the page is loaded, it looks and works exactly like your current page.

    Ok this is proving more difficult.
    By turning the html page into a php page, did you mean merely saving it as index.php as opposed to index.html?

    I have done the following but the html is not recognizing the php variable and the php echo command is not working at all, oddly. Bear in mind Ii have zero php experience up to now.
    <!DOCTYPE html>
    <html>
    <body>
    <?php
    echo "This is my basic web page to view a PDF file.";
    $filename = "filename"
    ?>
    <a href="yourfile.pdf" download= "$filename">Download the pdf</a>
    </body>
    </html>
    


  • Registered Users Posts: 225 ✭✭TheSetMiner


    Edit; Got it partially working now over here: http://tester12345.comoj.com/

    One problem I have run into is that I am not sure how to feed the php variable into the html tags. Feeding it in as download="$variable" just names the file $variable... Thanks for your help man


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    Looks like you got the variable too, I see that download link is working now.

    Congrats, you just built your first (ever so lightly) dynamic web page.

    For the benefit on anyone else that may want to try this, what did you wrap around the variable name to get it to display?


  • Advertisement
  • Registered Users Posts: 225 ✭✭TheSetMiner


    Graham wrote: »
    Looks like you got the variable too, I see that download link is working now.

    Congrats, you just built your first (ever so lightly) dynamic web page.

    For the benefit on anyone else that may want to try this, what did you wrap around the variable name to get it to display?

    No I didn't get the php variable yet, it is still saving as $filename. Any ideas there?


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    Ok, the web server doesn't know that the $filename in the link is actually php and not text/html.

    You need to wrap the variable in tags to tell the server it's php and it should be parsed before sending it off to the browser. You've already done that in lines 4...7


  • Registered Users Posts: 225 ✭✭TheSetMiner


    This is what I have now:
    <html>
    <head>
    <title>PHP Test</title>
    </head>
    <body>
    <?php
    echo "<p>This is my basic web page to view a PDF file.</p>";
    $filename = "filename";
    ?>
    <a href="yourfile.pdf" download= <? $filename ?>>Download the pdf</a>
    </body>
    </html>

    I figured the bit in the tags didn't recognize it as php so I put the tags around it. It hasn't solved the problem, however. So I will try a few more tweaks and hopefully I'll get it.

    Edit; Now it is downloading it under the default name; yourfile.pdf. So it seems to be ignoring the "download =" bit completely. hmmm


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    You already know how to tell php to send something to the browser. You did that on line 7 to output a string of text.

    Just as a test, add a new line below $filename = "filename";. On this newline, instead of outputting a string of text, output the contents of your variable.


  • Registered Users Posts: 225 ✭✭TheSetMiner


    Graham wrote: »
    You already know how to tell php to send something to the browser. You did that on line 7 to output a string of text.

    Just as a test, add a new line below $filename = "filename";. On this newline, instead of outputting a string of text, output the contents of your variable.

    Just tested that, it outputs it just fine. So the problem is encountered when feeding it into the html tags.


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    so you need to wrap the variable that isn't working with the same thing you used to wrap the php that is working.

    How about you start by duplicating the entire section that is working and removing all of the bits you don't need.


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    I'm off for a while TSM, this should keep you going for a while:

    You're here:
    <?php
    echo "This is my basic web page to view a PDF file.";
    $filename = "filename"
    ?>
    

    We'll check we can echo the $filename variable
    <?php
    echo "This is my basic web page to view a PDF file.";
    $filename = "filename";
    echo $filename;
    ?>
    

    OK it does something but it isn't a filename, it's the word "filename"

    How do we set the variable $filename so it contains yourfile.pdf

    When you've worked that out.....


    Later on further down the page (after the variable is set) we only want to echo out the variable (not set it again):
    <?php
    echo $filename;
    ?>
    

    hmm, looks big, can we tidy that up a bit:
    <?php echo $filename; ?>
    

    what happens if we put that into your html link in the exact spot you want the filename to appear?


  • Registered Users Posts: 225 ✭✭TheSetMiner


    How do we set the variable $filename so it contains yourfile.pdf
    I'm not sure what you mean. I thought all I wanted was to set my variable equal to the download text. Why am I now trying to set it equal to a pdf file? In any case, I can't seem to find out how to do this either. I assume it is more complicated that $filename = yourfile.pdf
    what happens if we put that into your html link in the exact spot you want the filename to appear?

    do you mean like this?
    <html>
    <head>
    <title>PHP Test</title>
    </head>
    <body>
    <?php
    echo "<p>This is my basic web page to view a PDF file.</p>";
    $filename = "filename"
    ?>
    <a href="yourfile.pdf" download= <?php echo $filename; ?>>Download the pdf</a>
    <?php
    echo $filename
    ?>
    </body>
    </html>

    I think I am getting a little confused here. If $filename is anything other than text in the above situation surely it doesn't make sense because this is setting the title of the downloaded file, right?


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    If $filename is anything other than text in the above situation surely it doesn't make sense because this is setting the title of the downloaded file, right?

    no problem, I think we got crossed wires somewhere. Where I was trying to get you to was setting the filename dynamically (your pdf).

    The idea being you define your filename as a variable (at the top of the page) then in the html, you use that variable as the download link.
    <a href="VARIABLE GOES HERE">Download the pdf</a>
    


  • Registered Users Posts: 225 ✭✭TheSetMiner


    Graham wrote: »
    no problem, I think we got crossed wires somewhere. Where I was trying to get you to was setting the filename dynamically (your pdf).

    The idea being you define your filename as a variable (at the top of the page) then in the html, you use that variable as the download link.
    <a href="VARIABLE GOES HERE">Download the pdf</a>
    

    Ah ok that makes sense, thanks. I'll try that now.


  • Advertisement
  • Registered Users Posts: 225 ✭✭TheSetMiner


    Great, got that working. Opening in new tab now too as opposed to downloading! http://tester12345.comoj.com/


    Thanks Graham. Where should I go from here?


  • Registered Users Posts: 225 ✭✭TheSetMiner


    OK so I am at a situation where I could, in theory, achieve my goal by uploading all my PDF files the way I have done here and then allow the user to find the ones they want. I could also have an email form on the site allowing users attach PDFs they would like to submit also, which I then could manually add myself.
    Something is telling me there is a far better, more automated way of doing this, however. Is my next step databases? I have little experience with mySQL. But research tells me I could use mySQL here and a thing called Sphinx to let users search the database. What do people think?

    Thanks for all your help thus far, particularly Graham!


  • Registered Users Posts: 2,781 ✭✭✭amen


    While this is a good learning experience what exactly are you trying to do ?

    Allow users to upload, search and download PDFs ?

    How do you handle security, updating of pdfs, multiple pdfs with the same names etc

    There are off the shelf solutions (might even be WP plugins) that do this for you.


  • Registered Users Posts: 225 ✭✭TheSetMiner


    amen wrote: »
    While this is a good learning experience what exactly are you trying to do ?

    Allow users to upload, search and download PDFs ?

    How do you handle security, updating of pdfs, multiple pdfs with the same names etc

    There are off the shelf solutions (might even be WP plugins) that do this for you.

    I am trying to make a site which allows users search for a specific code (of a couple of hundred codes) and then return all the PDFs in the databse entered under that code.

    Ideally they would be able to add PDFs themselves, assigning them to a code. But this isn't crucial initially, particularly if it is a lot more difficult to achieve.

    Hadn't thought there'd be solutions to this already out there, least of all a free one but if there is, that would be perfect I guess. I do intend to learn this stuff anyway though. :)


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    What you're looking for is a document management solution.

    There's hundreds out there, including WordPress plugins.

    Nice work over the weekend btw, it's well worth keeping that up.


  • Registered Users Posts: 241 ✭✭fcrossen


    Try:
    <html>
    <head>
    <title>PHP Test</title>
    </head>
    <body>
    <p>This is my basic web page to view a PDF file.</p>
    <?php $filename = "filename.pdf"; ?>
    <a href="<?php echo $filename ?>">Download the pdf</a>
    </body>
    </html>


  • Registered Users Posts: 3 alanda


    Edit; Got it partially working now over here: http://tester12345.comoj.com/pdf/view-pdf

    One problem I have run into is that I am not sure how to feed the php variable into the html tags. Feeding it in as download="$variable" just names the file $variable... Thanks for your help man

    Can I interpret your question as how to add & retrieve pdf from data base? If yes, I think maybe you can check whether this post can help you a little.:D

    http://www.vbforums.com/showthread.php?656899-How-to-add-and-retrieve-PDF-files-to-MS-SQL-server-database


Advertisement