Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Uploading files

innerHTML max_file_size

  • Please log in to reply
6 replies to this topic

#1 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 29 March 2008 - 06:49 AM


<html>
<head>
<script language="javascript">
fields = 0;
function addInput() {
if (fields != 10) {
document.getElementById('files').innerHTML += "<br /><input type='file' value='' name='file[]' />";
fields += 1;
} else {
document.getElementById('files').innerHTML += "<br /><span style=\"color:red;\">You can only have 10 upload fields.</span>";
document.upload.add.disabled=true;
}
}
</script>
<title>Upload File</title>
</head>
<body>
<form name="upload" enctype="multipart/form-data" action="uploader.php" method="POST">
<div id="files">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <br /><input name="file[]" type="file" />
</div><br />
<input type="submit" value="Upload File" />
<input type="button" value="Add more" name="add" onclick="addInput()" />
</form>
</body>
</html>


I have this HTML and a javascript that creates extra file upload fields at the user's choice. I want to be able to upload these to my server. I know how to upload one file but I can't get it to upload all the files that I want to upload.

Can anyone help?

Thanks,

~James
  • 0

#2 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 29 March 2008 - 02:50 PM

You need to change the name from "file[]" to a unique name for each upload. Then you can access the files as you would normally via PHP.
  • 0

#3 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 30 March 2008 - 02:48 AM

That would work but I'm having problems because when the user clicks to add another file upload field, I would need to add a name to it then.


<script language="javascript">
fields = 0;
function addInput() {
if (fields != 10) {
document.getElementById('files').innerHTML += "<br /><input type='file' value='' name='i' />";
fields += 1;
} else {
document.getElementById('files').innerHTML += "<br /><span style=\"color:red;\">You can only have 10 upload fields.</span>";
document.upload.add.disabled=true;
}
}
</script>


I have a file field in the body, and I know how to upload that but what my problem is, I don't know how to upload the files specified in the fields that the user adds to the page.
  • 0

#4 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 30 March 2008 - 05:45 AM

I don't see where you declare i or increase i's value. I would recommend adding i to "file" so file + i = "file1", "file2", etc.
  • 0

#5 phpforfun

phpforfun

    Speaks fluent binary

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1056 posts

Posted 31 March 2008 - 07:28 AM

I made a script just like this, the only thing id like to know is.. how do I add a progress bar?
  • 0

#6 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 08 April 2008 - 01:12 PM

I made a script just like this, the only thing id like to know is.. how do I add a progress bar?


Um I don't really know how with PHP but perhaps it might be possibly using PHP with ajax. not really sure
  • 0

#7 alilg

alilg

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 52 posts

Posted 08 April 2008 - 01:28 PM

Um I don't really know how with PHP but perhaps it might be possibly using PHP with ajax. not really sure

with php-perl and ajax or just php and ajax you can create a good progress bar!
when you clicked the UPLOAD button, a javascript timer will running during the file have sending to you server.
the ajax checking the size of the file which have upload, at you host "tmp" directory, every 6 seconds for example, and send it back to you html upload page... so simple..

there are many free scripte which you can download...
just try to google php ajax progress meter or ajax file upload progress and see
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download