how to preview uploaded image in php form - php

i created PHP form for my site, with image upload option on it.
but it only show the image name before image submitted, but i want to view/preview the image/file before submit so how this possible in this?
"file36":{"label":"Select/Upload a Student's Photo","accept":"jpg|jpeg|png|gif|bmt","files":true,"attach":true,"database":true,"maxbytes":204800,"fieldtype":"fileupload","required":true,}},

As far as I know this is not possible with php until you upload the image.
However, you are able to do so with jquery.
Check out http://blueimp.github.io/jQuery-File-Upload/

The old way is to upload the image to a temp folder, create an iframe and load the response there. Then link the temp image from the iframe to a hidden field in the final form with JavaScript. When you submit the form place the image in the right folder. Finally run a cron job every 24-48h to empty out the temp folder.
The new way is the File API supported in IE10+ and all modern browsers. Fallbacks in Flash and Silverlight exist for older browsers.

You obviously misunderstand how file uploads w/ PHP work.
PHP is server side programming language, meaning, it can only execute and access scripts, that are on the server. So, for PHP to access / analyze a picture in any way, it has to be on the server already.
You can upload the file in a temporary directory, analyze it and, if it suits your needs, move to a permanent folder. Otherwise, just delete it.

Related

Php Multiple Instance Upload Files at once on submit with Process On Second Page With Progress Bar

Sorry for my English, I had to use Google Translator
I have a form, in this form i have several input upload files.
What I'm trying to do is send the arquives at once to the next page. When its happen it darkens the page and shows a progress bar where it sends all files. Once you do it finishes recording in the database.
The files uploads is multiple instances
Found I multiple file uploads but no causes that I am wanting to do and do not know what I can do to get this result.
I can't use XMLHttpRequest but i can use APC
I do check the size and types of archives (PDF, JPG, ZIP)
I have an image that explains itself, see the link
Picture
Beside the fact that you cant use XMLHttpRequest, any ajax solution can't be used. But in my eyes this works only with ajax.
I recommend you to check out uploadify. There are several events fired on upload start and while uploading the file(s). Just take a look to the documentation! Also you can upload multiple files at once, without having several inputs for file uploading.
You can make on upload start (once, just set a var on upload start of the first file to true or something else, what indicates, that the upload has started) show a overlay-div with HTML-elements that simulate a progressbar. This progressbar can be updated by javascript while uploading. Uploadify should give you all information about the files and amount of bytes.
The upload and database part is handled by a php-file which can be specified by you.

Triggering a FLASH Event function

I am trying to build a simple application. The first phase is selecting to upload a file from the user desktop or from the site's gallery.
The question is if the user chose to upload from the gallery, say, go to an PHP page gallery, choose a photo and then redirected to the Flash app. How would you trigger the Flash up to know there was an image chosen and it should load it?
Does PHP send a variable or create an XML based on a choice and pass it via Flash variable, or does it need JavaScript to tell Flash that if the Flash var is not empty run this function? Could you please give a sample script I could work on?
Why are you starting the upload process outside of Flash when you want to use the file inside of the Flash application? Use FileReference to initiate the file upload, save the image name locally and have the php script you hand the file off to store the file in a known place, then listen for the Complete event. From there, you should be able to load the file into Flash from your server using the path "KnownDirectory/SavedFileName" with URLLoader.

Send image path via AJAX

so I have this form where I add item to my DB.
Fiedls are:
Name, Description, Image.
Problem is with image, I want to send the new values via AJAX using jQuery to my submit file. Reason for this is to not refresh any page. Everything is fine except IMAGE because browsers keep making the path private ex. "C:\fakepath\myImg.png".
Is it possible to somehow send my image path, because it works with default <form method="post...></form>, only problem is that it is refreshing the page, that's why I want to use AJAX.
Sorry, my native language is not English so maybe you didn't understand me clearly :)
I'm after full path to UPLOAD the image in my submit file. I can't upload image without knowing it's full path, can i?
You can use jquery.form plugin to upload forms without reloading the page.
Examples: http://www.malsup.com/jquery/form/#code-samples
The browser keeps making it a "private" path because the browser client has no knowledge of your server structure and it only knows the path where it is stored on the client machine. The upload goes to a temporary location on your server and it is up to you on the server side to move it from the temporary path to the place you want to store the file,
So in that sense, no you can't specify the destination path using AJAX.
In addition, you never want to allow the client to specify a location on your server. Even allowing them to specify the name that the file will be stored as is a potential security risk.

Free java or flash file browser for photogallery

I'm about to develop a small web gallery, where it's supposed to be possible to upload several pictures at a time and then add some info abut the pictures.So I need a free java or flash local file browser that can pass me some info of the pictures that gets uploaded so that I can create some SQL entries for each picture.
The platform for the project will be PHP and MySQL.
Any good recommendations?
I think what you are looking for is SWFUpload.
From the feature list:
Upload multiple files at once by ctrl/shift-selecting in dialog
Javascript callbacks on all events
Get file information before upload starts
Style upload elements with XHTML and css
Display information while files are uploading using HTML
No page reloads necessary
Works on all platforms/browsers that has Flash support.
Degrades gracefully to normal HTML upload form if Flash or javascript is unavailable
Control filesize before upload starts
Only display chosen filetypes in dialog
Queue uploads, remove/add files before starting upload

Image Preview using AJAX in PHP

How should i create a preview of image to be uploaded before it is actually submitted using AJAX in PHP?
Without uploading the image, this is going to be impossible in JavaScript as far as I can see, because security limitations are going to prevent you from determining the selected file in the file upload, and embedding that file in an img tag (as it used to be possible five years ago.)
You will be more lucky with Flash-based uploaders. I have seen some that offer the kind of functionality you want.
Update: Here's one that offers a preview function. From what I can see, it base64 encodes the local image and serves it to the surrounding HTML page as a inline data <img> tag. This is great because it might integrate well into your site. It does not work with any version of Internet Explorer, though.
Here's a fully Flash based solution that does previews in all browsers.
you first have to upload the document to server. Than you can show like.
<img src="uploads/file1_12224.jpg" />
The "file" input type doesn't expose the local file location of the file to be uploaded. It does "appear" to because as a user you can see the location, but the web page never knows this value. Without the local file address, you can't show a preview of the image on the web page using plain HTML or JavaScript.

Categories