corsasport.co.uk
 

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


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author PHP gurus
daymoon
Premium Member

Registered: 1st Aug 08
Location: Selby, North Yorkshire
User status: Offline
9th May 10 at 20:54   View Garage View User's Profile U2U Member Reply With Quote

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!
ed
Member

Registered: 10th Sep 03
User status: Offline
9th May 10 at 21:11   View User's Profile U2U Member Reply With Quote

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

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

Registered: 13th Sep 03
User status: Offline
9th May 10 at 22:33   View User's Profile U2U Member Reply With Quote

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
daymoon
Premium Member

Registered: 1st Aug 08
Location: Selby, North Yorkshire
User status: Offline
10th May 10 at 11:00   View Garage View User's Profile U2U Member Reply With Quote

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...
AndyKent
Member

Registered: 3rd Sep 05
User status: Offline
10th May 10 at 11:52   View User's Profile U2U Member Reply With Quote

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
ed
Member

Registered: 10th Sep 03
User status: Offline
10th May 10 at 12:17   View User's Profile U2U Member Reply With Quote

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.
xa0s
Banned

Registered: 4th Mar 08
Location: Dartford, Kent Car: Turbo'd Fabia vRS
User status: Offline
10th May 10 at 13:27   View User's Profile U2U Member Reply With Quote

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
Member

Registered: 10th Sep 03
User status: Offline
10th May 10 at 13:30   View User's Profile U2U Member Reply With Quote

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

Registered: 13th Sep 03
User status: Offline
10th May 10 at 22:38   View User's Profile U2U Member Reply With Quote

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.
xa0s
Banned

Registered: 4th Mar 08
Location: Dartford, Kent Car: Turbo'd Fabia vRS
User status: Offline
11th May 10 at 23:49   View User's Profile U2U Member Reply With Quote

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.
ed
Member

Registered: 10th Sep 03
User status: Offline
12th May 10 at 08:41   View User's Profile U2U Member Reply With Quote

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

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
Cooler Engine-disconnecting EGR? ffls Help Zone, Modification and ICE Advice 10 1150
18th Sep 03 at 17:35
by Juha GSi
 
Nice day so..... washed the car and took some pics! Rhino General Chat 29 1259
21st Apr 05 at 10:12
by Rhino
 
website/php/http gurus Dom Geek Day 6 295
30th Jun 05 at 16:18
by Ian
 
HELP!!!! Deekiboy Help Zone, Modification and ICE Advice 10 327
27th Jun 06 at 14:40
by Deekiboy
 
what car is this? ChazSXi General Chat 22 1099
14th Oct 07 at 04:02
by SVM 286
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP gurus 29 database queries in 0.0098898 seconds