Using JQuery or PHP to pull latest image? - php

I was trying to figure out a way to have JQuery (if possible) to display the latest image from a directory, regardless of its file name. Basically, I just want a simple tag to be updated to show the image. I realize this might not be possible with Jquery, so my fallback would be PHP.
I've been trying to research how to do this, but honestly do not know where to start. Any tips to get going would be greatly appreciated,

If you want to do it with JQuery, you can! You only need to add a few lines of logic to your app.
For example, when you add images to that folder, also write a text file with the name of the image just added. Then this text file is going to always have the filename of the last image uploaded. Finally, using JavaScript(with JQuery or anything else) you do one request to the text file and then you do the second request to obtain the image with that filename.
That is just a very basic example to try to share the idea of how to do it, then depending your particular case, you can add or change a lot of details to make this works for your case.
BTW, to do it with PHP, you are going to need to execute a system command, for example 'ls -ltrh' and parse the output to obtain the last filename.

You can use PHP script to get latest modified file in a specific directory.
Code can be found here: Get last modified file in a directory
You then can format that into JSON which can be passed through a jQuery AJAX call http://api.jquery.com/jQuery.ajax/
With those 2 techniques, you can manipulate the data to display the image.

Related

compose and upload a new article using a custom form

I'm starting to learn about php trying to achieve the goal of make my first custom form. From what I understand, it's possible to collect data from a form you can compose and customize to get information like title, subtitle, uploaded images and of course the main text of a supposed post and collect them in an html file that the form itself plus a php file can store in a folder on my server.
what i would like to understand better is if i can compose the form making it be able to include the collected information between pieces of code i don't wanna write anytime in the fields of the form. i also need to understand how to make it be able to save the final html file with a different suffix like an increasing number at the end of the name to be sure no older file created this way is going to be lost cause of overwrite.
the best would be a way to leave the last 5 documents i upload using this method with the suffix between 1 and 5 and rise the number of the older files, but that would be super fancy. doing so i wanna basically make myself a sort of backoffice for my website. I'm sincerely just trying to learn and do it in the most easygoing way so feel free to suggest me good guides if you know some, it would already be a nice help.
what i would like to understand better is if i can compose the form
making it be able to include the collected informations between pieces
of code i don't wanna write anytime in the fields of the form
this is not clear. please give an example.
i also need to understand how to make it be able to save the final
html file with a different suffix
if you really need to save forms data on disk, and avoid collision. you can generate unique id while writing the file as file name
see http://php.net/manual/en/function.uniqid.php
or using a composer package to generate uuid. see https://github.com/ramsey/uuid
while i still recommend using a proper data store, database or in memory.

Upload a pdf file without the actuall upload

Ones again I have a question which I hope to get help with.
I have a small database where I want to include information about the location of specific pdf files. This means that I am not saving the actual pdf’s just their location on a local drive.
The issue is that I don’t need to do any upload of the file since they are located where I want them to be beforehand.
My actual form code is a type="file" code with a browser button. It saves a copy of the pdfs into pdffiles map. What I want is to keep the browser button functionality but without the need of saving the files in the pdffiles map, plus that I want the saved pathway in Mysql code to be the original location of the file.
I hope you can understand what I am trying to achieve.
Thanks to you all!
Unfortunately, my knowledge in JavaScript is limited.
The form line I am trying to read is simple:
Say I have a file: C:\test\Ritningsregister\pdffile1.pdf
Like I said before all I want is to store the path info of the current file into MySql without any upload/download involved. I have been trying to use pathinfo($_FILES['filename']['name'], PATHINFO_DIRNAME) but it only gives me the relative path, ie .
pathinfo($_FILES['filename']['name'], PATHINFO_BASENAME) returns pdffile1.pdf as it should.
I have also trying to use realpath($_FILES['filename']['name']) hoping it will give me the whole path information: C:\test\Ritningsregister\ … without any luck.
What I at least could establish is that when I am trying to open a pdf file whose pathway has beforehand been imputed into MySQL say: C:/test/Ritningsregister/pdffile1.pdf. The browser had no problem in opening it.
So I really hope you can help me to solve this problem!
Best regards CaLey
[edit]
well what you could do then is use javascript to grab the value from the input-file and put that text into the value of a hidden input, and then reset the input-file so no file is uploaded. if you need help working out how to do this let me know :)
[edit]
are you just trying to process some file locations into a database ? as you can use php scripting to just read a directory's file's and then save that into a db without a form at all

is it possible to create an image from an url

i have an url="http://some url";
Is it possible to create an image of the url using php?
I tried using imagecreatefromjpeg but it accepts only image file as the input and not the url like "http://"
I'm not sure what you mean - do you mean create an image of the page
itself? Then yes, it's possible. All you need to do is parse the html,
fetch any css and parse it, add in images and process any javascript in
the page.
Of course, it might take you a few years to build such an application,
but it can be done. And at the end you'll have a browser written in
php, which will be quite slow.
If you need to take a snapshot of a web url using just php you need an external tool like cutycapt.
It is quite invasive for a server (you need an X environment) but it the easiest solution to go at present.
If you want to create an image with your url text in it then use something like, imagefttext, for more visit php.net/imagefttext, in case you want to take a screenshot of the webpage at given url, go to this SO link: Command line program to create website screenshots (on Linux)

dynamically scan pictures in a folder and display using jquery slideshow

anyone know how to scan a folder using jquery or javascript code snippet, after that get a picture file name and embed in <li></li> or <div></div>, i've used php code to read through the folder and loop through the element to display the thumbnails and all, but it's not work well.
I've try on galleria, gallerific, galleryView jquery slideshow plugin but those might not work well with php processing because of predefined configuration or something, can anyone tweak or hack these gallery to dynamically read an image from a folder?
There is a way to read local files using javascript, but it requires the user to set up his browser appropriately. I know about such feature in Firefox. In your case, the best way would be to use PHP for folder scan and Lightbox for image display (which in turn has slideshow plugins).
Perhaps you'd be better of saying what didn't work well when you tried the PHP path and we can help you fix that?
Your best bet is probably going to either be an existing thing such as Gallery as powtac mentioned, or if you are only wanting to display images from a single folder that might be a bit of overkill.
You could use PHP to output the thumbnails and whatever other information you need into a list of <li> tags, use CSS to hide some of them (if required) and then use Lightbox or any of the many other JS image galleries available to do what you want.
Then you can ask on here if you are having trouble with one of those steps (detailing what you are doing, what's going wrong etc).

Using PHP to generate screenshots from an HTML source

I've got an idea for a site that would generate png or jpeg screenshots of webpages on the fly. The end user would never see the pages, but the HTML would be turned into a screenshot instead and the end user would see that screenshot.
How can I get started on this? I guess what I'm looking for is some kind of PHP function that takes the HTML as an argument and then produces an image file in a specified location.
As far as I know, PHP does not do this.
You can, however, find a solution using external tools.
Here is how I would do it
Generate the HTML
I would pass this HTML to a external tool using exec. There is, for instance this one.
Then, display the generated picture
http://www.zubrag.com/articles/create-website-snapshot-thumbnail.php

Categories