0

Moral: I'm using AJAX to upload a profile picture on the registration page.

Issue: When I upload an image it auto updates the database without the need of a page request so it needs a _iD ( user id/uid ) to upload to the database. As there isn't an available _iD because the visitor isn't registered it cannot update the database.

Looking for solutions: *How would I accomplish to uploading the picture and preview it without the need to UPDATE my database before pressing submit button, as the AJAX needs to AUTO UPDATE my database to uploda the file with the _iD ( user id ). Do I need to set a temporary _iD which will be used to created the account once the submit form is requested?*

-->register.php

-----> http://pastebin.com/kZE4B105

-->*register_image_upload.php*

-----> http://pastebin.com/15n4pgPJ

-->Database table

-----> users

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|  _iD   | _iPassword |  _iUsername | _iEmail        |   _iProfilePicture  |
|  40    |    bcrypt  |    _iUser   | blah@gmail.com |         $PATH       | 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

EDIT: Current error on form when image uploaded.

Warning: move_uploaded_file(profile_pic/_iThumbnail/1369388350.jpg): failed to open stream: No such file or directory in C:\EasyPHP-12.1\www\public_html\register_image_upload.php on line 18

Warning: move_uploaded_file(): Unable to move 'C:\EasyPHP-12.1\tmp\php7EFB.tmp' to 'profile_pic/_iThumbnail/1369388350.jpg' in C:\EasyPHP-12.1\www\public_html\register_image_upload.php on line 18
failed
Attis
  • 124
  • 13

3 Answers3

1

I know it is very old question , but may be useful for others ..

You are using ajax , so you can do things in following manner-

  • send the file and get the image file name through ajax call when successfully uploaded.

  • Change the src of image (where to show ) what you got by the ajax call.

  • you may use a hidden field which will contain the src of image.

  • now , when the form will post , get data from that hidden field .And do manipulation as you were doing in database..

If you get any confusion , please comment , so i will get back to discussion.

Rohit Kumar
  • 1,948
  • 1
  • 11
  • 16
0

why not preview on the client side, before the upload actually occrus? see thisstack post

Community
  • 1
  • 1
Sagi Mann
  • 2,967
  • 6
  • 39
  • 72
0

You can store image in a temp directory and a link to that image in a session. When user completes registration move the image to permanent storage and update user profile.

claustrofob
  • 5,448
  • 2
  • 19
  • 22