PHP Content Type Download Tutorial

PHP Content Type Download Tutorial

PHP Content Type Download Tutorial

Today we add to the scenario 3 of PHP Content Type Iframe Synchronize Tutorial as shown below, from two days ago, by adding a new button for some Download functionality usage.

With PHP, the difference between a download scenario, and normal “inline” web usage (ie. web pages only affect your hard disk in terms of whatever caching the web browser does), is via the use of PHP’s header method’s use of “Content-disposition” within the raw HTTP header that the PHP header method assembles. So when we use …


header('Content-Type: ' . $ct);
header('Content-Disposition: attachment; filename="' . $dlsuggestion . '"');
echo file_get_contents(urldecode($_POST['selname']));

… we are using a Download mode of use (where that PHP $dlsuggestion variable is derived, perhaps, from the URL in $_POST[‘selname’]), as distinct from the normal mode of use via …


header('Content-Type: ' . $ct);
header('Content-Disposition: inline');
echo file_get_contents(urldecode($_POST['selname']));

Above we are talking about the (phase 2) callback scenario of php_content_type.php but what of the mechanism for making this happen?

Well, we just add a fourth button as per the HTML …


<input type='button' onclick=' downloadit(); ' title='Would prefer //www.rjmprogramming.com.au URL please' value='Download PHP Content Type' id='viadownload'></input>

… and use the Javascript onclick functionality (and you’ll see that we introduce an id= to the HTML form to facilitate this new idea) …


function downloadit() {
var mf=document.getElementById('mform');
mf.action += '?download=y';
mf.submit();
}

So, with your day’s rest from it (are you rested?!), have a go at a live run if you like, or take a butchers at the PHP source code you could call php_content_type.php that changed as per php_content_type.php as far as added Download functionality is concerned.


Previous relevant PHP Content Type Iframe Synchronize Tutorial is shown below.

PHP Content Type Iframe Synchronize Tutorial

PHP Content Type Iframe Synchronize Tutorial

Today, again, we drill deeper into the scenario 3 of PHP Content Type Primer Tutorial as shown way below, two days ago.

Today we put in functionality to place your URLs, the “s” of which was inspired by the work of yesterday’s PHP Content Type Iframe Overlay Tutorial as shown below, into an HTML form element that, again, can be rePOSTed back to our PHP web application php_content_type.php so that we can start (the web application execution) afresh with the chance to Synchronize (via an HTML form submit button) media files you may want to play, for instance.

You’ll probably find impediments to Synchronicity with mobile platform usage, but we’ll just see how it goes for now. If you read this blog often, perhaps you remember a previous incarnation of web applications to Synchronize with PHP/Javascript Media Synchronize Cross Browser Tutorial. It is definitely a topic where cross-browser and cross-platform issues come into play.

So, again, have a go at a live run if you like (and note that you can suffix your URLs with ?wording=[a_caption] or &wording=[a_caption] for explanatory wording functionality, as required), or take a geek at the PHP source code you could call php_content_type.php or take a peek at the changes made to yesterday’s efforts at php_content_type.php … and we hope it helps you out with a web application idea you have.


Previous relevant PHP Content Type Iframe Overlay Tutorial is shown below.

PHP Content Type Iframe Overlay Tutorial

PHP Content Type Iframe Overlay Tutorial

Today we drill deeper into the scenario 3 of yesterday’s PHP Content Type Primer Tutorial as shown below.

In the process we discover another concept for the “overlay” ideas we present at this blog. It is not that we haven’t done this before, in a sense, but that we haven’t tagged it as an idea in the category (or “tag” (chortle, chortle)) of “overlay”, but we need to talk about it … you first … ooooookay … an HTML iframe element that has its src= parameter be dynamically changed is another way to think of a concept of “overlay” … okay, it’s out there … do with it what you will! Call up the president on the red phone, or pick the yellow phone and speak to your Avon representative.

But, seriously, this is serious … can’t you tell?!

What we want to point out about that src= value to dynamically change is that it can be like yesterday’s call with a PHP content type (or mime type) that is not your usual “text/html”. Is THIS of more interest now?!

But, seriously, this is serious … you can tell … we changed the font size … now THAT‘s serious.

The upshot is, that this may mean you can synchronize media perhaps (and perhaps you were a reader when we did tutorials like PHP/Javascript Media Synchronize Cross Browser Tutorial (which attempted synchronization of media) earlier at this blog), or what we do today with our tutorial picture, and allow for the piecing together of a “home cobbled” slideshow, a common overlay “suspect”. We allow for the “Add” option rather than “Overlay” as well, to open up a new HTML iframe on the fly, so to speak.

If you ever use the wonderful Gifpal to create your animated GIFs, we hope to have achieved something just a tad similar, in that, once you enter in a new URL, it is added into the slideshow dynamically, probably not as cutely as Gifpal, but there’s an element of cuteness to seeing a slideshow presentation dynamically change … or it could be that the writer is easily amused!

So have a go at a live run if you like, or take a gecko at the PHP source code you could call php_content_type.php or take a squizz at the changes made to yesterday’s efforts at php_content_type.php


Previous relevant PHP Content Type Primer Tutorial is shown below.

PHP Content Type Primer Tutorial

PHP Content Type Primer Tutorial

Today we want to start a discussion on a big topic in web programming, the webpage content type (or mime type).

The normal association of webpages is with the …


text/html

… mime type. Server side languages such as PHP and ASP.Net, for the most part, create webpages in HTML format, but they don’t have to. Supposing you have some PDF data then you can use PHP’s header method to use (the snippet from today’s PHP php_content_type.php) …


<?php
// ...
// no echo statements anywhere up here
// ...
header('Content-Type: ' . $ct);
echo file_get_contents(urldecode($_POST['selname']));
?>

… to show a webpage using a mime type defined by the PHP variable $ct which is “application/pdf” in the URL “HTTP://localhost:888/logo.pdf” of our example tutorial picture.

We show this distinction today by writing a PHP web application that in the first instance is a web page consisting of an HTML form as per …


<form target='_blank' action='./php_content_type.php' method='POST'>
...

… the “target=’_blank'” of which is ensuring a new webpage will be opened and by saying “method=’POST'”, on submission, would POST (into $_POST[‘selname’]) to itself (in a new webpage) the HTML input type=url as per …


Url: <input type='url' name='selname' id='selname' style='width:70%;' value='//www.rjmprogramming.com.au/MyBusinessUnidad/Welcome_files/logo.jpg'></input>
...

… the user defined URL of interest.

In the second instance, or the callback scenario, the php_content_type.php code analyzes $_POST[‘selname’] to derive a file extension (if none, would assume a mime type of text/html). That file extension we map against the very useful sitepoint resource we thank very much to arrive at a suitable mime type to be suitable for that PHP $ct variable we talked about earlier. This gives us the scenario used for the middle of three buttons …

  1. Navigate via Web Browser … up at the web browser address bar you’ll see the Url of your data source
  2. Show via PHP Content Type to New Webpage … up at the web browser address bar you’ll see the Url of php_content_type.php (which got POSTed to … so no $_SERVER[‘QUERY_STRING’] even)
  3. Show PHP Content Type Below … ie. to an HTML iframe, the scenario of today’s tutorial picture

With scenarios 2 and 3 above there is no hope that View->Page Source nor This Frame->View Page Source will result in a happy readable result, where scenario 1 will sometimes allow for this.

With this knowledge in mind, or by trying a live run, maybe now, some of the mystifying address bar URLs you encounter surfing the net may be more explainable to you … hope so. Understanding of this topic can be a “light bulb” moment for many people, and a little bit of patience can reveal many possibilities with web applications, should you delve deeper yourself.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in Animation, eLearning, Event-Driven Programming, Tutorials and tagged , , , , , , , , , , , , , , , , , . Bookmark the permalink.

33 Responses to PHP Content Type Download Tutorial

  1. Auto Parts says:

    You can definitely see your expertise within the work you write. The arena hopes for more passionate writers like you who are not afraid to mention how they believe. At all times go after your heart.

  2. Peter says:

    Hello, interesujΔ…cy rozdziaΕ‚. Dawno nie czytaΕ‚em tak fajnego pisarstwa.

  3. I would like to express some thanks to the writer just for bailing me out of such a situation. As a result of browsing throughout the online world and seeing tricks which were not productive, I assumed my life was over. Existing without the solutions to the difficulties you’ve resolved through this guide is a crucial case, and the kind that might have badly damaged my career if I had not discovered your web blog. Your expertise and kindness in controlling almost everything was invaluable. I don’t know what I would have done if I had not encountered such a subject like this. It’s possible to now look forward to my future. Thanks so much for your reliable and sensible guide. I will not be reluctant to recommend your blog post to anyone who needs to have recommendations on this subject.

  4. Alexander says:

    Witaj, interesujΔ…cy artykuΕ‚. Pewien czas nie widziaΕ‚em tak ciekawego tekstu

  5. Gaming says:

    fantastic issues altogether, you just won a new reader. What would you suggest in regards to your submit that you simply made some days in the past? Any positive?

  6. Real Estate says:

    Hiya, I’m really glad I’ve found this info. Nowadays bloggers publish just about gossips and net and this is actually irritating. A good site with interesting content, that’s what I need. Thanks for keeping this website, I will be visiting it. Do you do newsletters? Can not find it.

  7. You made some clear points there. I did a search on the subject and found most persons will go along with with your blog.

  8. Moving says:

    I was just searching for this information for a while. After 6 hours of continuous Googleing, at last I got it in your site. I wonder what’s the lack of Google strategy that do not rank this kind of informative web sites in top of the list. Usually the top sites are full of garbage.

  9. I was just searching for this information for some time. After six hours of continuous Googleing, finally I got it in your site. I wonder what is the lack of Google strategy that do not rank this kind of informative sites in top of the list. Normally the top sites are full of garbage.

  10. champion says:

    Some truly wonderful information, Glad I detected this. “With silence favor me.” by Horace.

  11. her response says:

    Liking the article.. thanks alot :) My web browsings seem total.. thank you. My browsing efforts seem total.. thank you. I value you giving out your perspective..

  12. certainly, research is having to pay off. Isn’t it superb once you get a very good post? Supporting the posting.. thank you so much Liking the blog post.. regards

  13. It‘¦s actually a nice and helpful piece of info. I‘¦m happy that you shared this useful info with us. Please stay us informed like this. Thank you for sharing.

  14. I have recently started a site, the information you offer on this web site has helped me tremendously. Thank you for all of your time & work.

  15. small says:

    Pretty section of content. I just stumbled upon your website and in accession capital to assert that I acquire actually enjoyed account your blog posts. Any way I will be subscribing to your feeds and even I achievement you access consistently fast.

  16. You actually make it seem so easy with your presentation but I find this matter to be actually something which I think I would never understand. It seems too complex and very broad for me. I am looking forward for your next post, I’ll try to get the hang of it!

  17. Mirana Terry says:

    I think other site proprietors should take this site as an model, very clean and wonderful user friendly style and design, as well as the content. You are an expert in this topic!

  18. I was just looking for this information for a while. After six hours of continuous Googleing, finally I got it in your web site. I wonder what is the lack of Google strategy that do not rank this kind of informative websites in top of the list. Normally the top web sites are full of garbage.

  19. Youre so cool! I dont suppose Ive read anything such as this before. So nice to get somebody with some original thoughts on this topic. realy we appreciate you starting this up. this fabulous internet site are some issues that is required on the internet, somebody with a little originality. beneficial function for bringing a new challenge on the world wide internet!

  20. All systems says:

    Thank you, I have recently been looking for info approximately this topic for ages and yours is the greatest I’ve found out till now. However, what concerning the conclusion? Are you certain about the source?

  21. Would really like to always get updated excellent site ! .

  22. Yours is really a prime example of informative writing. I think my students could learn a whole lot from your writing style and your content. I may share this article with them.

  23. fortunate says:

    My web browsings seem total.. thank you. Great ideas you’ve got here.. Adoring the write-up.. cheers Very beneficial perspective, many thanks for posting..

  24. Rachel Gaska says:

    paper rollÒ€¦ maintain up your informative writing! At least i’ve something to look forward too when iam at function!Ò€¦

  25. Following I initially commented I clicked the -Notify me when new feedback are added- checkbox and now each time a remark is added I get four emails with the same comment. Is there any method youÒ€ℒll be able to take away me from that service? Thanks!

  26. Timeless says:

    Excellent views you have got here.. Definitely handy perception, appreciate your writing.. indeed, research is having to pay off. Respect the posting you made available..

  27. Bright says:

    Mighty effective point of view, thank you for writing.. I enjoy you posting your viewpoint.. Loving the contribution.. pleased So content to get identified this publish..

  28. You have remarked very interesting points ! ps nice web site . “The appearance of right oft leads us wrong.” by Horace.

  29. Enjoyed studying this, very good stuff, appreciate it. “Nothing happens to any thing which that thing is not made by nature to bear.” by Marcus Aurelius Antoninus.

  30. Generally I don’t read post on blogs, but I wish to say that this write-up very compelled me to take a look at and do so! Your writing style has been surprised me. Thank you, quite nice article.

  31. Mickey says:

    I am requesting my mom. She does not necessarily want to generate income off them, her function is to use her blog (once popular) and use it as references to perhaps help her get a news article. She has a title for one called “Answers to Life’s Problems”. Where can she publish blogs as well as they come to be preferred? She published it already on WordPress yet there are 3 million individuals publishing blogs hers gets lost in the mix. Any type of pointers?.

  32. Violin says:

    Hello to every one, it’s truly a pleasant for me to pay a visit this web page, it contains priceless Information.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>