How do I show a link once a file is uploaded - php

I had trouble finding an answer for this problem. I would like to display a link to a page that has a video file on it but I don't want the link to appear until after the video file is uploaded.
It's a site where users upload videos so I don't want to have to manually put the links there for them after they upload their videos, nor do I want to make the links ahead of time since users will click them and there will be no video available.
So, is there a way to keep a link hidden until a file is uploaded. Once the file is uploaded the php page where the link will be on checks to see if it exists and then if it does the link is shown, otherwise the link stays hidden.

Each time the form that the client uses to upload a file is sent store the information of the file in a database.
Each time the client request the list of videos, query the database and build the web page based on the results.
Make sure to associate the uploaded files to the users, so you don't mix the up. Are you managing authentication already?
If you want to have the links appear as soon as the upload is finished without reloading the page, then you need ajax.

Related

Disable direct links to images on an expired or unpublished Blog Post on a custom PHP web application

I have a custom PHP simple Blogging web application where users can upload a blog post with photos and file attachments. They can unpublish their posts or set it to expire on a certain future datetime.
When I load the blog post on my website, say mydomain.com/post/100. I am showing a gallery of uploaded photos.. they are loaded via direct links for example mydomain.com/images/photo1.jpg etc. I am also showing file attachments and they are linked via direct links like mydomain.com/files/file1pdf etc.
When the post expires or intentionally unpublished, these direct links are still loading the photos and files.
So, to hide the file URLs, I have a ‘viewscript’ instead .. I am obfuscating the attached file link to mydomain.com/viewfile/xyz123 which the server code links to the specific post and checks if it is published and not expired and then downloads the file to the reader’s browser. This works for files. And on each click to the link.. or a direct access to the file, it is a single database query to check if the Post is still valid.
How do I do this for Images / Photos uploaded to the Post? I can do the same ‘viewscript’ .. but that means making a call to the database for each photo that is uploaded to the Post. I would like to disable direct link access to photos uploaded to a Blog post that is unpublished or expired.
Any suggestions or ideas? Thank you.

Found some 404s for image files in statistis

I am running a website in which I generate dynamic images for users. Initially, I was saving all the images generated forever so that I can use those images when required to be shown again but since recently I started getting some decent traffic, so I thought instead of saving and reusing the images I should generate them again when they need to be shown again.
Now what I am doing is: I have created a temp folder and I save every image in that temp folder and show it to user. And when this image is required to be shown again, I just re-create that image instead of using this temp image. And temp folder is now emptied at sometime daily.
But now I have started getting 404s in my error logs for the images. I am not getting that from where I am getting those 404s since I myself tried deleting image from tmp and then revisited that page. The image was re-created and was shown properly. I am badly stuck at this. One thing I would like you to tell is that I am allowing user to share those result-pages(with images) on social networks.
So it is like:
I create one image in tmp and show it on some result.php page. I
also put the image's link in og meta tag so that it can be properly
identified by social networks while sharing.
If somebody visits result.php page again, then it shows image again. However, if image is not available(i.e. deleted as daily
job), then it recreates it first, saves at that location and then
shows the page.
I am getting 404s for .jpg image files in error log.
On debugging it more, I found that these 404s are there because of access to images from Facebook IPs. The IPs from which 404s are detected are like: 66.220.158.119, 173.252.101.116, etc. On some googling, I founf that these IPs are allocated to Facebook.
So it means: facebook bot is accessing the images because these links were earlier shared on facebook via facebook share. Can someone please tell me is there any harm if later(say after 1 day of sharing), if facebook does not find the image anymore on my server? Will it not show anymore on shared link on facebook also?

How to make an image selector to choose an image from the server to use in HTML form

I have built a blog system where each entry has an associated image file. I have created a php upload for this system and can get everything onto the server. When I write each blog post I have a row in my database which stores the filename of the image, so I could, if I knew the filename already, just type it in.
What I want to do is on my blog post form, instead of being able to type the file name, I want a button to click on which opens a window with all my images in it, then I can click on one and have that filename sent back to the form.
I suppose I could use AJAX to do this but it seems over complicated. Does anyone know of a good way to achieve this.

Displaying images in webpage from HTML

I have a script where by users upload an image on a website and the image gets uploaded to an FTPServer. The name of the file is stored in a database, so when users click on a link, the query string is used as a reference in the Database to get the image name. The only part I'm stuck on right now, is how to display the image on my webpage using php. Is there a specific function to get a copy from the FTP server and display the image? I dont want do download the image to the web server, and then display the image and then delete it, as this could take up a lot of space if the web site has many visitors.
The "big image hosts" typically have web access to their "storage servers" as well. So when a file is uploaded to their image server it's accessible with a URL. You'd want to determine the url that points to the file you just uploaded and place that in your html (in the img tag. Let the user's browser retrieve the image, as opposed to your web server first retrieving it and then displaying the page.
You have to store the image on the web server, once you do that you can display it on your web page however you like, php, ajax, javascript, your choice.

Upload multiple files while navigating other pages - howto?

I'm creating a website and I'd like to allow users to upload multiple files while they navigate the website.
When the upload completes, it would be nice to have a Javascipt event triggered, to allow the user to specify additional info related to the uploaded files (eg. photo location, tags, etc)
anyway, the required features are:
multiple files allowed for a single upload operation
display an optional progress indicator (at least in the "x of y files uploaded" fashion)
doing it without tying the users to a single page
How can I implement these features?
Any suggestion is greatly appreciated!
Edit
In the event of using a popup window to handle uploads, how can I:
inform the user (on the "master" page) that the upload has completed, or that there have been errors?
(more important) pass the $_FILES array to the popup window? I'd like the user to be able to click "upload" on the main window, or anyway to make the upload start from the main window (eg dragging and dropping files on the main window).
Since navigating the site will switch pages and it's unlikely that there's a full ajax navigation on your site, maybe it could help to somehow upload the files in a second popup window. Not sure how (if) it could be implemented, though, but since you need to upload multiple files at a time I'm afraid you're bound to use flash.
EDIT
So the solution could look like this:
When a user clicks a "select files" button you pop out a new window where he'll be able to actually select files (via flash if multifile upload is necessary). And to notify of upload progress use postMessage. Though postMessage isn't going to work in IE in this case, but probably you could somehow send the message to the server and from the server back to the page.
Another crazy idea is not to use a popup window, but let the user select the files on the page she was first, but once the user selects the files make all the links on the page target=_blank to make any subsequent navigation happen in another tab. I know it's hacky and not exactly user-friendly, but probably could help.
In any case I would inform the user beforehand that a new window will appear in both scenarios.
EDIT2
And an even crazier idea. When the user selects the files and clicks a link create an iframe which will cover the whole page and hide the original page beneath it and make the links open in the iframe. But it looks even more hackish and it seems you'll have much trouble with it.

Categories