corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP gurus » Post Reply

Post Reply
Who Can Post? All users can post new topics and all users can reply.
Icon:
Formatting Mode:
Normal
Advanced
Help

Insert Bold text Insert Italicized text Insert Underlined text Insert Centered text Insert a Hyperlink Insert Email Hyperlink Insert an Image Insert Code Formatted text Insert Quoted text
Message:
HTML is Off
Smilies are On
BB Code is On
[img] Code is On
Post Options: Disable smileys?
Turn BBCode off?
Receive email notification of new replies?

ed

posted on 12th May 10 at 08:41

For starters it's not even AJAX. You couldn't use AJAX in that situation even if you wanted to.


xa0s

posted on 11th May 10 at 23:49

quote:
Originally posted by ed
It's hardly complicating it. The script is all in here give or take a few additions... http://valums.com/ajax-upload/

No, it's definitely complicating it... If he has to ask for help doing something simple like this then introducing Ajax as well isn't a great idea. :boggle:


Dom

posted on 10th May 10 at 22:38

quote:
Originally posted by daymoon
Sorry, maybe i wasnt clear.

I have a working file upload script, what i want is when i have uploaded an image, for it to be displayed next to form...


Once you've moved the file (from temp directory to root or wherever), then simply echo out an IMG tag with the image in it, eg: echo "<IMG src=\"",$filelocation,"\">"; (commas on echos are fine by the way)

If you already have a basic PHP upload then i wouldn't worry about AJAX or JQuery/Flash uploads, can always add them in afterwards if it will get your more marks.


ed

posted on 10th May 10 at 13:30

It's hardly complicating it. The script is all in here give or take a few additions... http://valums.com/ajax-upload/


xa0s

posted on 10th May 10 at 13:27

Why complicate it with Ajax? When the file is submitted it changes page anyway so just display the image. The hard bit is already done...

Post your current code so we can see what you've done.


ed

posted on 10th May 10 at 12:17

There are two ways of doing it. Synchronously using pure PHP, so you'd upload the file then on page reload after the upload had commenced you would use some PHP to display the image. You could do it Asynchronously using Javascript. The script I suggested will do what you're trying to do, and in fact I have an avatar upload script which does exactly what you're trying to do. The user uploads their avatar, the upload script handles the upload along with the PHP stuff to do the file handling and when the upload is complete the PHP script returns some JSON to say that it's all worked and tells use the new filename. The upload script then uses that JSON message to figure out if something has gone wrong or if the pic has uploaded. If the pic has uploaded you use document.getelementbyid.('image_id').src= to change the src of the existing image to the new image.


AndyKent

posted on 10th May 10 at 11:52

Can you not just write it yourself?

In your form create a space for an image which doesn't have any code inside it but is styled to hold the space.

eg. <div style="width:250px; height:250px"></div>

Then with Ajax as Dom has described write in the img tags after the image has been uploaded in the background.

Thats what I'd do. It'd take me longer to find the existing code on the net than to code it :lol:


daymoon

posted on 10th May 10 at 11:00

Sorry, maybe i wasnt clear.

I have a working file upload script, what i want is when i have uploaded an image, for it to be displayed next to form...


Dom

posted on 9th May 10 at 22:33

You can do a very basic file upload using the form file input (type='file') and then use $_FILES[] to save the uploaded file that you can recall (ie: display) later - http://www.tizag.com/phpT/fileupload.php

Ed's posted a pretty decent JQuery upload, you still deal with $_FILES on the php side of things but it makes the client side easier.

Personally i've always used a combo of JQuery and Flash (something like uploadify) as it allows more control of filesize and allowed extentsions, plus file progress (although you can do this via AJax i believe) and file queuies (plus a load more call backs). PHP side of things is pretty much the same as all PHP uploads and client side is all handled via JQuery.

If you stuck with the PHP side of things, you basically want to check to see if a file has been uploaded ($_FILES['yourfileinputname']['name'] gives original filename or $_FILES['yourfileinputname']['size'] gives file size), if it has then you want to move the file from the temporary directory (use move_uploaded_file($_FILES['yourfileinputname']['tmp_name'], 'directorylocation')) and if that is successful then you basically echo out the location of the moved file to a IMG tag.

http://www.php.net/manual/en/features.file-upload.post-method.php


ed

posted on 9th May 10 at 21:11

I use this script: http://valums.com/ajax-upload/

It's a nice and tidy way of doing things...


daymoon

posted on 9th May 10 at 20:54

Trying to make a simple website for my uni project and got to use php..

WHat i need is a smple script for following:

User uploads picture into a form
picture appears on the screen next to form for user to make sure they uploaded correct picture..

HELP!