How to group files together in upload - php

What is the most efficient way to group a bunch of file uploads together on the following screen? I currently have http://blueimp.github.io/jQuery-File-Upload/ implemented on one of my websites, and I use a hidden field with some random generated id that gets passed into the next page. This has proven to be unreliable, and I was wondering if someone had a better way of making sure all of the XHR files responses are grouped together on the next page?
Thanks.

Not 100% sure what you mean by grouping the files, but if you want to make sure the files are legit, perhaps using a SESSION key will help.

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.

Heatmap in PHP, using mysql database

I've currently got a database with just short of 2000 client locations in Australia. What I am trying to do is to display this data on a heatmap, to be embedded into an existing website.
I've done a heap of looking around, and can't seem to find exactly what I'm after.
http://www.heatmapapi.com/sample_googlev3.aspx
http://www.heatmaptool.com/documentation.php
These are along the right lines of what I want to achieve, however I cannot see these working with data from a mysql database (require the data to be hard-coded, or uploaded through CSV files).
Has anyone come across this sort of thing before, or managed to achieve it?
Both of the examples you provide would potentially work.
With the first you would need to use the data you have to dynamically generate the javascript, or at least the values that go into the javascript.
The second is probably the better option. You would provide a path to the script that would dynamically generate a CSV file.

The best way to show lots of images in one .php page

I want to upload around 1,000 small (let's say 50x50) photos in one .php page. Could I do it without cracking the browser? Maybe there are optimization for images or something like that? How would you do that?
It's theoretically possible, but it's unclear whether browsers will handle it nicely. I can certainly see it being a pain for users.
You might be better off asking users to upload a single file (like a .zip) containing the images, and let the server unpack it and process the contents.
You could use PHP to put all the filenames into an array, then loop the array with whatever you wanna do with them.
I personally am assuming this is not something for users, but something for you to just let run? Otherwise this would be a really bad idea to implement for your users, might break something...or cause problems on your own server.

What is the best way to keep track of images uploaded by an user using PHP

I am planning to do a photo album website, So each user may upload as many number of images. What is the best way to keep track of images for an individual user. What should be the server configuration to handle this part.
-Lokesh
Depending on the amount of images, you will probably want to store them on a static domain. Then, have a table in whatever database you are using to store the paths to each of the images for each user.
Well like many design topics there are lots of different ways to go about it. Two ways that come to mind right now are as follows.
you could simply have a directory created on the server for each user and then have the images each use uploads saved into that directory. Ofcourse you'd want to make sure they didn't over write any existing images with images of the same name. You could do this by warning them about conflicting names or by adding some sort of noce string (like a time stamp) to the end of of the file name. This is a pretty straight forward solution and means that you can login to your server and see all the images each user has uploaded right there for you to do anything you like with.
Another idea would be to save the images in a database. This can be done by serializing the images to a string and storing it in a database. This is nice becaues it means you don't have to worry about handling directories and duplicate file names. You will have to deserialize each image when you want to display it which will put your DB under load so for a very high traffic volume site this might not really be the way to go.
There are ofcourse combinations of these ideas and many others. It really comes down to working out which solution best fits your exact needs.

Linking an image to a PHP file

Here's a bit of history first: Recently finished an application that allows me to upload images and store them in a directory, it also stores the information of that file in a database. Database stores the location, name and gives it an ID (auto_increment).
Okay, so what I'm doing now is allowing people to insert images into posts. Throwing a few ideas around on the best way to do this, as the application I designed allows people to move files around, and I don't want images in posts to break if an image is moved to a different directory (hence the storing of IDs).
What I'm thinking of doing is when linking to images, instead of linking to the file directly, I link it like so:
<img src="/path/to/functions.php?method=media&id=<IMG_ID_HERE>" alt="" />
So it takes the ID, searches the database, then from there determines the mime type and what not, then spits out the image.
So really, my question is: Is this the most efficient way?
Note that on a single page there could be from 3 to 30 images, all making a call to this function.
Doing that should be fine as long as you are aware of your memory limitations configured by both PHP and the web server. (Though you'll run into those problems merely by receiving the file first)
Otherwise, if you're strict about this being just for images, it could prove more efficient to go with Mike B's approach. Design a static area and just drop the images off in there, and record those locations in the records for their associated post. It's less work, and less to worry about... and I'm willing to bet your web server is better at serving files than most developer's custom application code will be.
Normally, I would recommend keeping the src of an image static (instead of a php script). But if you're allowing users to move them around the filesystem you need a way to track them
Some form of caching would help reduce the number of database calls required to fetch the filesystem location of each image. Should be pretty easy to put an indefinite TTL on the cache and invalidate upon the image being moved.
I don't think you should worry about that, what you have planned sounds fine.
But if you want to go out of your way to minimise requests or whatever, you could instead do the following: when someone embeds an image in a post, replace the anchor tag with some special character sequence, like [MYIMAGE=1234] or something. Then when a page with one or more posts is viewed, search through all the posts to find all the [MYIMAGE=] sequences, query the database to get all of the images' locations, and then output the posts with the [MYIMAGE=] sequences replaced with the appropriate anchor tags. You might or might not want to make sure users cannot directly add [MYIMAGE=] tags to their submitted content.
The way you have suggested will work, and it's arguably the nicest solution, but I should warn you that I've tried something similar before and it completely fell apart under load. The database seemed to be keeping up, but the script would start to time out and the image wouldn't arrive. That was probably down to some particular server configuration, but it's worth bearing in mind.
Depending on how much access you have to the server it's running on, you could just create a symlink whenever the user moves a file. It's a little messy but it'll be fast and reliable, and will also handle collisions if a user moves a file to where another one used to be.
Use the format proposed by Hammerite, and use [MYIMAGE=1234] tags (or something similar).
You can then fetch the id-path mappings before display, and replace the [MYIMAGE] tags with proper tags which link to images directly. This will yield much better performance than outputting images using php.
You could even bypass the database completely, and simply use image paths like (for example) /images/hash(IMAGEID).jpg.
(If there are different file formats, use [MYIMAGE=1234.png], so you can append png/jpg/whatever without a database call)
If the need arises to change the image locations, output method, or anything else, you only need to change the method where [MYIMAGE] tags are converted to full file paths.

Categories