0% found this document useful (0 votes)
6 views2 pages

Stackoverflow Com Questions 13794204 Successful File Upload

The document discusses issues with a file upload form that allows empty uploads, causing server errors, and opens a blank page after submission. It suggests that server-side validation is necessary to handle bad data and recommends preventing the default form submission behavior using JavaScript. The user is open to replacing the existing code to resolve these problems.

Uploaded by

stppp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Stackoverflow Com Questions 13794204 Successful File Upload

The document discusses issues with a file upload form that allows empty uploads, causing server errors, and opens a blank page after submission. It suggests that server-side validation is necessary to handle bad data and recommends preventing the default form submission behavior using JavaScript. The user is open to replacing the existing code to resolve these problems.

Uploaded by

stppp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

successful file upload opens new blank page, Ask Question

also allows "empty/blank" to upload


Asked 12 years, 2 months ago Modified 12 years, 2 months ago Viewed 644 times

following code is working but with 2 issues: It is part of bigger form on the web page it appears
on.
0
<FORM id="my_file_upld_form"
style="display: inline;"
METHOD="POST"
ACTION="/cgi-bin/fileupload_ajax.pl"
ENCTYPE="multipart/form-data">
<INPUT TYPE="file" class="ajaxfileupload" NAME="myfile" SIZE="42">
<input type="hidden" class="ajaxfileupload" name="fileupload" value="ajax_fil
<input class="ajaxfileupload" type="submit" value="Upload"/>
</FORM>

1. it is allowing "blank" or empty (no file selection and upload button clicked) to upload. which
is causing 500 error on server.

2. bigger problem is: after the file is uploaded, a new blank page is opened in browser and
user has to use back button to go back to the page from where this was run. This happens
irrespective of the fact that the ajax script returns anything back or not.

how to fix? I am open to replace this piece of code on the page, if needed.

html ajax file-upload

Share Improve this question Follow edited Dec 10, 2012 at 4:12 asked Dec 10, 2012 at 2:30
Rajeev
1,371 7 29 48

Add a comment

1 Answer Sorted by: Highest score (default)

It's hard to tell exactly what is going wrong without your java script code. However I think I
know how to fix some of your problems.
0
1. Don't trust the client you need to handle in your backend code the ability to handle a form
that gives you bad data. You can validate the form client side but you always need to
validate server side as well.

Explore our developer-friendly HTML to PDF API Printed using PDFCrowd HTML to PDF
2. I suspect this problem is happening because you aren't preventing the default event in
javascript. In jquery you would do

$("#my_file_upld_form").submit(function(e){
e.preventDefault()
})

Share Improve this answer Follow answered Dec 10, 2012 at 4:33
powerc9000
2,103 20 31

Add a comment

Not the answer you're looking for? Browse other questions tagged html ajax file-upload or
ask your own question.

Explore our developer-friendly HTML to PDF API Printed using PDFCrowd HTML to PDF

You might also like