Jump to content

Zane

Administrators
  • Posts

    4,362
  • Joined

  • Last visited

  • Days Won

    11

Posts posted by Zane

  1. Define "no longer being watched".  The video ending is pretty clear, but not being watched could be a number of things.

    • No longer in window scroll view
    • Video has been stopped
    • Video has been paused

    How are you streaming this mp4?  Though an HTML5 player?  Or, do you have a specialized library for outputting the video to a specific third-party video player?  Or, perhaps a own roll-your-own version of a video player?  In any case, these events should be available from the video player itself.  PHP is just going to grab the mp4 and output it for the video player to use.

  2. //Generate the link
    
    $normalText = "this is just your average string with words and stuff";
    
    $hashedText = md5($normalText);
    
    fopen($hashedTest, 'w');
    
    echo "<a href='validate.php?video={$hashedText}'>Link to the video</a>

    This generates a file named 06d5f7c7c17f15f1b28374b16c64e38d, and a link to validate.php?video=06d5f7c7c17f15f1b28374b16c64e38d

    Then, on validate.php, you'd use the concept I put in my last post.

     

     

  3. Wherever you generate your link to the video at, you'll need to add a hash to a database.  The generated link should pass a GET parameter with the hash.

    http://mymp4.com?validate.php?video=40f677a45113eb829e345d278b8d1d31

    Then, access your database and look for that hash.  If it exists, delete it and output the video using the code that's already been provided in this post.  That's probably the most minimalist way that I can think of.  You could just skip the database altogether and store the hash in a txt file that's not publicly accessible.  Same concept.

    Here's an example.

    In this case, the hash is the name of the file.

    A video will download the first time, but when you try to access it again with the same link, it fails.

    <?php
    $v = $_GET['video'] ?? null;
    
    if(file_exists($v)) {
    	unlink($v);
    	header('Content-type: application/mp4');
    	header('Content-Disposition: inline; filename=video.mp4');    
    	readfile("./mytestvideoo.mp4");    
    } else
       http_response_code(404);

    This isn't secure whatsoever, so I wouldn't just copy and paste this.  People could essentially just type in the name of one of your files and it would be deleted.

  4. This should do it.

    <?php
    $text = <<<T
        Our final Beaver Fever Friday of the year was yesterday.  What a show.  It's always nice to get to know these seniors over their careers.  Here are the interviews if you missed them:
        Christa Benson - Track <a href="http:///beaverradionetwork.com/audio/1011/brnpodcasts/BFF2019/ChristaBenson.mp3">Christa Benson - Track</a><br /><br />
        Cody Cook - MGolf <a href="http:///beaverradionetwork.com/audio/1011/brnpodcasts/BFF2019/CodyCook.mp3">Cody Cook - MGolf</a><br /><br />
    T;
    $text = preg_replace("/<a.+href=(\"|')([^\"']+)(\"|').+<\/a>/", 
                         "<audio controls> <source src=\"\\2\"  type=\"audio/mpeg\"> </audio>", 
                         $text);
    echo $text;
    
    ?>


     

  5. Well, then, if that's the case,  you can use regular expressions to extract the value from the alt tags of the image tags.

    /<img.*alt=["|']([^"']+)["|']/gm

    https://regex101.com/r/26vszE/1

    Though, that regex won't work right if the filename has an apostrophe or double quotes.  Anyway, that's what I'd use to extract all of the image filenames in the alt tags of incoming HTML.  Storing the incoming HTML in a BLOB column shouldn't be an issue.  Store it encoded and decode it when you take it out.  Not hash it.  Hashing is another thing altogether.

  6. The more you reply with details the more it makes me understand that you're trying to extract the images from incoming HTML.  Am I correct on this?

    39 minutes ago, mark107 said:

    I have got emails that come with images in the HTML so I'm storing them in a db. I have got no idea how to store the DATA in a db when I'm fetching my emails using imap.

     

  7. What you do is maintain a normalized database.  In other words, have a table for anything that you'd consider to be an important chunk of data.  For instance, attachments.  Ideally, you'd have an attachments table in your database.  Within this table, you want to put as much about each attachment as you can, as columns (table fields), with the ultimate goal being to have only one single unique row per attachment.  One attachment cannot be another.

    Here's a rundown of what I think you're looking at for a table schema.

    • id - you need a primary unique identifier for every attachment
    • email - Which email is this an attachment of?  You'd put an id in here that correlates to a specific email in another table called "emails".
    • image - Again, images are a good example of another good chunk of data.  So, put an id of an image from another table called "images".  This way you don't restrict images just to attachments.  Images lives matter too.  You could store everything about every image on your site in this table.  You can even give it a label to use for whatever reason you'd need a name for the image that isn't the filename.
    • filename - Obviously, this would just be a string containing the filename, and the filename only.  You might decide to change your URL structure one day, or reorganize folders, so just keep the filename.

    That's probably the most fundamental minimum schema you'd have.  Then, you have the emails and the images to store in their own separate tables.  Again, bare minimum:

    Emails Table

    • id - primary unique identifier for the email.
    • user_id - Assuming you have a user management system set up, I'm willing to bet there is a unique identifier for every user.  There's another table worth creating!
    • destination_address - What is the email address this message was sent to?
    • body - What is the message body of this email?
    • sent - Is this message sent?  Blink once for yes and zero times for no -- That's binary.
    • send_date - When was this message sent? Use a UNIX timestamp so you can output the date precisely as you want to.  Now, and in the future when you make decisions about change and stuff.

    For something like the "body" of an email, it's probably one of the few times it'd actually be logical to store HTML (that is encoded).  It's not likely you're going to change the way an email looks that has been sent.  For example, say you're on a mailing list for some site -- Site A.  If, for whatever reason, Site A decides to change their mailing list format that is sent out, you'd still be able to look at older emails from the mailing list and see what they've changed.

    Then, when all the proper SQL queries have been executed by a server side language, such as PHP, you can use that same language (PHP) to dynamically generate HTML.  Need a dropdown showing a list of all users?  Create a function that'll generate a <select> tag with <option> tags for each user.  Then, you just slap that sucker in whatever HTML you have set up and pretty it up with CSS.

    <div id="attachments">
    
         <div id="attachment_{$attachment_id}">
    
              <a href="{$attachment_filename}"><img src="somefolder/images/{$image_filename}" /></a>
    
         </div>
    
    </div>
    

    Where {$variable} is one of your PHP variables that contains the data you need.

    Look up Database Normalization on Google.  Get a feel for how data should be treated.  This is a decent article on it.

  8. Composer creates an autoload file that you can include at the top of your PHP scripts instead of having to include every package individually.  Then you just have to use them as if they're classes that you've included.

    https://getcomposer.org/doc/01-basic-usage.md#autoloading

    Example from site.

    require ( __DIR__ . '/vendor/autoload.php';
    $log = new Monolog\Logger('name');
    $log->pushHandler(new Monolog\Handler\StreamHandler('app.log', Monolog\Logger::WARNING));
    $log->addWarning('Foo');

     

    • Like 1
  9. I don't see where you are sending information to any PHP page when clicking an image.

    For instance, all of the images you have have an onClick value that pops up a confirm box, that's it.

     onclick="return confirm('Set ALL status to Upcoming Release?')"

    And it's not like you can call a PHP function onclick either, so don't think that's what I'm getting at.  You need a JavaScript function that sends an AJAX call to the PHP file.   Just clicking an image will not cause a <form> element to submit.  So, either correct your onclick, or create a JS snippet that handles clicks on images within that form and submits the form.

  10. String.replace() takes a second argument, the replacement.  You're better off just overwriting the location property.

    window.location = 'validate_attendance.php?emp_num='+emp_num;

    Also, what is the point of declaring a function that takes an argument and then overwriting that argument immediately?

        function ValidateEmployeeNumber(emp_num) {
            //completely destroy the value for emp_num and create it again?
            var emp_num = document.getElementById("emp_num").value;
            window.location = 'validate_attendance.php?emp_num='+emp_num;
        }

    If this is the approach you're going to use, then either take the parameter out of the function (and the call) or just don't overwrite the variable.

  11. If you didn't know already, the way you are outputting those values is by the use of what's known as a ternary operator.  It generally works like a miniature IF statement.  You have a condition clause, a true clause, and a false clause. 

    (condition) ? (what to do if true) : (what to do if false);

    In your case right now, you're simply checking to see if a value is empty or not, by using PHP's empty function.  And, if you look in the manual, you'll see that what the empty() function takes a variable and returns to you a true/false value depending on if the variable is in fact empty or not.  Or, in the words of the manual:
     

    A variable is considered empty if it does not exist or if its value equals FALSE. empty() does not generate a warning if the variable does not exist.


    What you're asking for is how to change that condition to mean "is it greater than zero?" and that's as simple as changing the condition to be $total1 > 0

     

    Essentially making it this

    $var = $total1 > 0 ? true : false;

    You're wanting to echo things so using simply true or false in the above example won't work.  You'll have to replace those with strings.

    echo $total1 > 0 ? "greater than zero" : "not greater than zero";
  12. It is indeed more challenging than HTML!  HTML is a markup language (hence the 'ML' in the abbreviation), PHP is a server-side programming language.

     

    Hopefully you learn something here to help you meet your goals.  Welcome to PHPFreaks!

  13. Do you know where I can find the answers to the reinforcement exercises in this book to help the person I tutor out?

    In order to answer that, we'd need the actual questions wouldn't we?

     

    This person really needs help and I am not classified as a teacher so I cannot get my hands on the actual answers to this book thanks.

    Why are you tutoring him/her then?

×
×
  • 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.