Uploading a file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

Uploading a file

Post by HiddenS3crets »

I have a register form that allows a user to upload an icon.

My scripts look alright, but the problem is that the $_FILES variable is not storing any information about the file being uploaded; I think it may be because I'm not loading a complete new page. Instead my form sends user data to a javascript function which then sends a post request to a register script.

Code: Select all

<?php
// Not storing anything (register script)
$_FILES['icon']['tmp_name'];
?>
I'm not quite sure, but I think the problem is that I'm not loading a new page so there's no way to update the $_FILES['icon'][*] fields.

How can I get around while still keeping intact my current setup?
tapas_bahirbag
Forum Newbie
Posts: 14
Joined: Sun Aug 06, 2006 6:54 am
Contact:

Post by tapas_bahirbag »

You must have to use
enctype="multipart/form-data"
this in the form tag of your register form.

--
Tapos Pal
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

Post by HiddenS3crets »

I do have that
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Post more code.
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

Post by HiddenS3crets »

This is a simplified version of my code.

Code: Select all

<form enctype='multipart/form-data' action='javascript:register()' method='post'>

Code: Select all

<input type='hidden' name='MAX_FILE_SIZE'  value='100000' />
<input type='file' name='icon' />
The javascript function register() then sends post information to the signup script

I try to echo $_FILES['icon']['name'], but there is no value there. To go broader, $_FILES is empty.

Why isn't the information being inserted into the $_FILES array?

Update: I noticed that if I post directly to the signup script and skip the javascript information is inserted into $_FILES, which is good, but the format of the site needs the javascript middleman. Is there a way that this information can be sent so I can keep my javascript intact?
Last edited by HiddenS3crets on Sat Jul 14, 2007 11:04 pm, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why is your action Javascript?
Post Reply