Current location: Hot Scripts Forums » Programming Languages » PHP » problem upload image with AJAX


problem upload image with AJAX

Reply
  #1 (permalink)  
Old 01-19-08, 10:08 AM
mahmoud82's Avatar
mahmoud82 mahmoud82 is offline
Wannabe Coder
 
Join Date: Nov 2006
Location: Jordan
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
problem upload image with AJAX

hi guys

iam working on script that upload image using Ajax but i have some problem with it.

first when i send the image file from the ajax to the php page the file dose not send with correct data. this is the print of array requist file
PHP Code:

Array ( [myfile] => Array ( [name] => image001.jpg [type] => [tmp_name] => [error] => [size] => ) ) 

why the eror is 3 and the size is zero

if you want i can send you the script.

thanx guys.
__________________
Their is no 100% secure system. ZCE
Reply With Quote
  #2 (permalink)  
Old 01-19-08, 10:16 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
AJAX doesn't support file uploads. Can you post your code?

As for the error number 3, it means:
Quote:
Value: 3; The uploaded file was only partially uploaded.

http://www.php.net/features.file-upload.errors
Reply With Quote
  #3 (permalink)  
Old 01-19-08, 10:18 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Edit: Too slow on the post button...

This is the meaning of the error -

Quote:
UPLOAD_ERR_PARTIAL
Value: 3; The uploaded file was only partially uploaded.
As to why it fails, you would need to post your code.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #4 (permalink)  
Old 01-19-08, 10:21 AM
mahmoud82's Avatar
mahmoud82 mahmoud82 is offline
Wannabe Coder
 
Join Date: Nov 2006
Location: Jordan
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
this is the script file
Attached Files
File Type: zip ajax_upload.zip (2.9 KB, 226 views)
__________________
Their is no 100% secure system. ZCE
Reply With Quote
  #5 (permalink)  
Old 01-19-08, 10:34 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Nico View Post
AJAX doesn't support file uploads
Are you sure? I could be wrong, but doesnt cPanel use ajax? on that you are able to upload files in the browser without refreshing in cPanel 11 on the file upload part

Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #6 (permalink)  
Old 01-19-08, 10:40 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
It's probably something tricky with iFrames. I'm very sure AJAX doesn't support file uploads.

Perhaps the progress bar involves AJAX or something.
Reply With Quote
  #7 (permalink)  
Old 01-19-08, 10:42 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Ah i see. thats way too over my head lol
Just found this also searching for "does ajax support file upload" on google

"Certainly, it is not possible, as the XMLHTTPRequest object that is used internally to post the form does not support file upload"
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #8 (permalink)  
Old 01-19-08, 11:01 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I've checked mahmoud82's code, and I would not suggest using it. IF it worked, then only on IE (because it requires ActiveX), and besides that, I don't see how this would work at all. It sends headers to the PHP script, but not the actual file.

There are better scripts out there. Try Googling for another one. (If you search for "AJAX Upload", you'll find scripts, even though none of them actually uploads using AJAX)
Reply With Quote
  #9 (permalink)  
Old 01-19-08, 11:02 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
I'll echo what Nico has stated. Uploads using a HTML form without refreshing the page are done with a hidden iframe. Search for Ajax file upload scripts to find many examples.

Another way of doing this so that the page does not reload is to use flash - http://www.swfupload.org/
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #10 (permalink)  
Old 01-20-08, 03:08 AM
mahmoud82's Avatar
mahmoud82 mahmoud82 is offline
Wannabe Coder
 
Join Date: Nov 2006
Location: Jordan
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
oky guys, thanx for ur helpful notes, i will try today to do it with actionscript, hope can i do it.
__________________
Their is no 100% secure system. ZCE
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple image upload lewiscornwell Job Offers & Assistance 2 11-21-07 06:14 PM
Image upload problem - error display sugarplum PHP 0 02-02-06 02:48 PM
Image Upload Perms automatically set to 600 progress Perl 2 10-05-05 12:19 PM
ASP upload prob minority ASP 1 06-27-05 08:35 AM
Image upload and if / else mdhall PHP 4 11-14-04 03:12 PM


All times are GMT -5. The time now is 07:33 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.