473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

File upload problem(firefox works, IE not)

db
Hi@all,

I am always thinking that there is no problems that I can not solve.
But now i changed my idea......

And I have posted it in javascript group, since i think both javascript
and php are involved in this problem, i post it here as well. If that
is "illegal", please delete it, thanks.
My problem is that i use javascript to generate a form, the form
contains a normal file uploader. The code is somehow like this:
var inputform =
document.getElementById('inputform');
if (!inputform) {
inputform =
document.createElement('form');

inputform.setAttribute('enctype','multipart/form-data');

inputform.setAttribute('method','post');
inputform.setAttribute('action',
'programMotes.php');
filetext=document.createTextNode(' Mote
Executable: ');

exefile=document.createElement('input');
exefile.setAttribute('type', 'file');
exefile.setAttribute('name',
'moteProgramFile');
text2=document.createTextNode(' ');

inputButton=document.createElement('input');
inputButton.setAttribute('type',
'submit');
inputButton.setAttribute('value',
'Flash the marked motes');
hidden =
document.createElement('input');
hidden.setAttribute('type', 'hidden');
hidden.setAttribute('name', 'sent');
hidden.setAttribute('value', 'true');
inputform.appendChild(tbl);
inputform.appendChild(filetext);
inputform.appendChild(exefile);
inputform.appendChild(text2);
inputform.appendChild(inputButton);
inputform.appendChild(hidden);
br=document.createElement('br');
br2=document.createElement('br');

finishedText=document.createTextNode('Loaded.');
inputform.insertBefore(br, filetext);
inputform.insertBefore(finishedText,
br);
inputform.insertBefore(br2,
finishedText);
content.appendChild(inputform);
}
And then in corresponding php file moteProgramFile.php:
$target_path = "uploads/";
$target_path = $target_path .
basename($_FILES['moteProgramFile']['name']);
echo $target_path;
if(move_uploaded_file($_FILES['moteProgramFile']['tmp_name'],
$target_path))
{
echo "The file ". basename(
$_FILES['moteProgramFile']['name']).
" has been uploaded";
}
else
{
echo "There was an error uploading the file, please
try again!";
}
With using firefox, there is absolutely no problem, but with using IE,
the file can just not be uploaded! Does someone have an idea?
thanks in advance
db

Jun 13 '06 #1
13 11780
"db" <ad******@gmail.com> wrote in message
news:11**********************@h76g2000cwa.googlegr oups.com...
Hi@all,

I am always thinking that there is no problems that I can not solve.
But now i changed my idea......

And I have posted it in javascript group, since i think both javascript
and php are involved in this problem, i post it here as well. If that
is "illegal", please delete it, thanks.
My problem is that i use javascript to generate a form, the form
contains a normal file uploader. The code is somehow like this:


TLDR (Too Long, Didn't Read)

With using firefox, there is absolutely no problem, but with using IE,
the file can just not be uploaded! Does someone have an idea?


Well what is the nature of the error? Have you tried examining the $_FILES
array? var_dump($_FILES). What does $_FILES['moteProgramFile']['error']
show? Does the form not build? Why do you use javascript for building the
form? If you had a similar but static form, would that upload anything in
IE?

For debugging try to leave all the textnodes out, all unnecessary fields,
leave just the form, the file field and submit button to narrow down the
problem. Then describe what appears to be happening once you've selected a
file and hit the submit. Then attatch the output of var_dump($_FILES). Then
there's a remote chance someone could actually manage to help you.

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Jun 14 '06 #2
db
Hi, thanks for replying!

Well what is the nature of the error? Have you tried examining the $_FILES
array? var_dump($_FILES). What does $_FILES['moteProgramFile']['error']
show? Does the form not build? Why do you use javascript for building the
form? If you had a similar but static form, would that upload anything in
IE?


Yes, i have. The $_FILES array is totally empty.
$_FILES['moteProgramFile']['error'] doesnt contain anything either. I
have to use javascript since i am using AJAX to save page loading time.
Actually what i do is using javascript to make a request to a php
function, this php function will provide certain XML stream
dynamically. According to the XML stream, certain table is build. If i
just use static form, IE works without any problem.

Furthermore, i have embedded a hidden field inside the form to check
whether the form is really submitted. And it does......

Now i dont know how to keep on going, please HELP!

thx

db

Jun 14 '06 #3
Try this, I remembered that setAttribute() should be avoided.

inputform.enctype = 'multipart/form-data';
inputform.method = 'post';

Jun 14 '06 #4
db

the DtTvB wrote:
Try this, I remembered that setAttribute() should be avoided.

inputform.enctype = 'multipart/form-data';
inputform.method = 'post';


Thank you, but this does not work either......

db

Jun 14 '06 #5
What about making a div that contains HTML in it?

Example is:
formdiv = document.createElement('div');
formdiv.innerHTML = '<form action=".....">\
Don\'t forget to use backslashes after each line!\
</form>';

Jun 14 '06 #6
db

the DtTvB schrieb:
What about making a div that contains HTML in it?

Example is:
formdiv = document.createElement('div');
formdiv.innerHTML = '<form action=".....">\
Don\'t forget to use backslashes after each line!\
</form>';


Actually I am using div now. In the html part:

<div class="csc-header csc-header-n1" id="dynamiccontent">Loading WSN
status...</div>

and in the javascript part, firstly i get the div with using
var content =
document.getElementById('dynamiccontent');

and then generate form, after that i use
content.appendChild(inputform)

Is that right?

db

Jun 14 '06 #7
db wrote:
and in the javascript part, firstly i get the div with using
var content =
document.getElementById('dynamiccontent');

and then generate form, after that i use
content.appendChild(inputform)

Is that right?

db


What I meaning was:
var content = document.getElementById('dynamiccontent');
content.innerHTML = ''
+ '<form action="..." method="post" enctype="multipart/form-data">'
+ '<input ..../> or some stuff like that.'
+ '</form>';

Jun 14 '06 #8
db

the DtTvB schrieb:
What I meaning was:
var content = document.getElementById('dynamiccontent');
content.innerHTML = ''
+ '<form action="..." method="post" enctype="multipart/form-data">'
+ '<input ..../> or some stuff like that.'
+ '</form>';


That should work, i think. But the problem is the form contains a
dynamic table, if i do like above, i can not append that table to the
form, or?

thanks anyway

db

Jun 14 '06 #9

db \/\/|20+3:
if i do like above, i can not append that table to the form, or?


You can.

content.innerHTML = ''
+ '<form action="..." method="post" enctype="multipart/form-data">'
+ '<table><tr><td>'
+ 'something and something......'
+ '</td></tr></table>'
+ '</form>';

Jun 14 '06 #10
db
You can.

content.innerHTML = ''
+ '<form action="..." method="post" enctype="multipart/form-data">'
+ '<table><tr><td>'
+ 'something and something......'
+ '</td></tr></table>'
+ '</form>';


Sorry, maybe i can not take your suggestion, since the dynamic table is
generated by another person, what i can use is only the object which is
fetsched by
var table = document.getElementById(tablename)

of course i can get HTML through table.innerHTML, but there are too
many things to change, i can not afford such a big operation.

What the hell is wrong with setAttribute()??

thanks anyway

db

Jun 14 '06 #11
db \/\/|20+3:
of course i can get HTML through table.innerHTML, but there are too
many things to change, i can not afford such a big operation. OK, maybe you should try this:
OK, what about this one?

var content = document.getElementById('dynamiccontent');
content.innerHTML = ''
+ '<form action="..." method="post" '
+ 'enctype="multipart/form-data" id="inputform></form>';
var inputform = document.getElementById('inputform');

(We have a form in content div already, then add elements to the form.)

db \/\/|20+3: What the hell is wrong with setAttribute()??

I don't know, they said it should be avoided.
exefile.setAttribute('type', 'file'); // Try change thid too.

Jun 14 '06 #12
db
Hi, thanks man,

With removing the weird setAttribute method, it works now under IE. I
dont know why the javascirpt ppl wrote these stuffs whereas they can
not work!

Thanks a lot!

I searched somehow in internet, and got these information, maybe that
will be helpful for someone who has the same problem as me:
// we want an onclick on this button for
example
field.onclick = functionName;

Don't use setAttribute and getAttribute, except when there is no other

way
to do what you want to do.


I wouldn't go that far, since the W3C DOM prescribes
setAttribute()/getAttribute() as the way to write/read attribute values.


True, but in practice I found that many problems can be avoided by
avoiding
set/getAttribute when possible. It's about the only more or less
general
rule I found for using the W3C DOM, so I repeat it whenever I have the
chance.
That said, setAttribute() doesn't work for event handlers in IE (Win/Mac).
For some reason IE doesn't resolve the value to the function object, so
nothing happens at event time.
Well well, interesting. I didn't know that.
It does work in Mozilla, however, and can be
beneficial in some cases: creating an event handler call that passes
arguments consisting of values assembled in the script setting the
attribute (rather than relying on the event object's properties for
details).
I hadn't thought of that.
In any case, to assign (or reassign) an event handler on the fly, event
handler property assignment, as shown above, is the way to go if you need
to serve IE in your audience browser mix.


<plug type="shameless">

On my W3C DOM mailing list (http://www.xs4all.nl/~ppk/js/list.html) we
often
discuss problems like this one. Event handler registration, especially,

turns out to be a rather problematical area with many small browser
problems.

If you're interested in getting the DOM to work in all browsers you
might
consider joining the list, as many JavaScript developers have done
before
you.

Jun 19 '06 #13
db \/\/|20+3:
If you're interested in getting the DOM to work in all browsers you might consider joining the list, as many JavaScript developers have done before you.


Cool, thanks you for it!

Jun 20 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: manika | last post by:
Hi, I am trying to upload a file and then copy it to a different destination. I use File.Copy.For some files I get "File not found" exception when I try to use the File.copy utility while others...
1
by: bissatch | last post by:
Hi, I am currently working on a content management system where a user can fill in a form (title, keywords, link text etc. - all the initial attibutes), which when submitted, will go onto create...
4
by: Brian K. | last post by:
I am trying to split up and secure a database that we've been using on a network for a few years, following the procedure listed in Q304932 from microsoft. I create a new blank database for...
0
by: Dithos | last post by:
Hi all, I hope somebody will be able to help me here and i am in a predicament as to how to solve this problem.i have been trying it since a week. i have 3 projects, say A, B and C. A is a...
3
by: gomzi | last post by:
hi, When I try to upload something using the fileupload control that comes with .NET I keep getting a file not found exception. This below piece of code throws up this error....
5
by: =?Utf-8?B?Um9u?= | last post by:
I am writing out some files, using this syntax: FileStream fw = File.OpenWrite(Filename); fw.Write(bytearray,0,amount); fw.Close(); The files appear in Windows Explorer, they show up from the...
0
by: fantasticamir | last post by:
I have a simple program using a couple of classes and it compiled successfully but while it is linking I have the following problem: g++ -Wall -lcu -lglu ACL2MDD.o Link.o Rule.o reachability.o ...
4
by: minhtran | last post by:
Hi All I create web page as ASP.NET . The program runs on localhost no problem,but when we upload on server has an error as : An unhandled exception occurred during the execution of the current web...
8
by: Brett | last post by:
I wrote an ASP.NET application that queries a SQL Server database (on a different box from the web server) and displays the result in a GridView. The datasource for the GridView is a SQLDataSource....
6
by: mlevit | last post by:
I'm trying to upload a file. I use to get the fread(): supplied argument is not a valid stream resource error, but then I placed the code in an if statement with file_exists. The problem is, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.