Cannot upload file through HTML form - php

I am planning to make a form which has a form through which users can upload a file on the website.
I used a CSS template where a class called pop-up-wrapper and pop up is defined. However, when I use the following code :
<div>
<div class="form-pop-up">
<div class="form-pop-up-wrapper">
<ul class="contact-form">
<form id="form-submit" method="post" enctype="multipart/form-data">
<li>
<p class="iam-white center-al">Upload file</p>
<input type="file" name="resume" id="user-resume">
</li>
<li>
<p> </p>
<input type="submit" name="submit" value="Submit" id="form-submit" class="mar">
</li>
</form>
</ul>
</div>
</div>
</div>
I have a PHP code which validates if any file has been entered by checking with
isset($_FILES['file']
but this always returns 0.
Is there anything in the CSS stylesheet which can lead to this situation where $_FILES is unable to catch the uploaded file?
TIA

You have to use the name in $_FILES, not the type.
isset($_FILES['resume'])

Just a shot here, but I don't think it's your CSS that's causing the problem. Try:
isset($_FILES['resume'])
instead.

Related

Broken file upload with bootstrap

With Bootstrap 4.0.0
<div class="container">
<div class="jumbotron mt-3" style="padding: 0.6em 1.6em;">
<h4>Uploader</h4>
<form enctype="multipart/form-data" action="/myurl/?action=upload" method="POST">
<input type="file" class="form-control-file">
<input type="submit" class="btn btn-primary" name="Upload">
</form>
</div>
</div>
In combination with this PHP code on the other side:
<?php var_dump($_FILES); ?>
returns:
array(0) { }
In other words: I simply select a file, /myurl/?action=upload is called, but empty($_FILES['myfile']) is TRUE / no files seems to be passed.
What is the issue?
Thanks
The issue is that you haven't provided a proper name attribute in your input field.
<input type="file" class="form-control-file" name="uploaded_file">
Would likely help this issue, but without seeing your PHP, it could be other issues.

Selecting file names from a folder in php

I want to get folder name from my computer in PHP code. I got the following piece of information, on searching on stackoverflow:
<input type="file" name="folder" webkitdirectory directory multiple/>
Directory Chooser in HTML page
But, the issue is the folder gives only one file name in post array.
<?php
echo "I am in page.";
if ( empty($_POST['folder']))
{
?>
<form method="POST">
<div class="container compare_body">
<div class="row">
<div class="col-md-3">
Select a Folder:
</div>
<div class="col-md-3">
<input type="file" name="folder" webkitdirectory directory multiple/>
</div>
<div class="col-md-3">
<button type="submit" class="btn btn-info">List your files</button>
</div>
</div>
</div>
</form>
<?php
}
else
{
print_r($_POST['folder']);
echo "I am in else.";
}
?>
I am in page.WWW.YIFY-TORRENTS.COM.jpgI am in else.
Edit : I tried GET method, which results in the following query:
http://localhost/thrillermovie/yourmovies?folder=2.png&folder=facebook_post.png&folder=callhistorycontrol.png&folder=khan.jpg&folder=minimization.png&folder=obama_knows.png&folder=facebook.png&folder=wildkrafts.png&folder=dekho.png&folder=sub.png&folder=2_batman.png&folder=best+response.png&folder=moore.png&folder=admob.png&folder=adrspeechcode.png&folder=batman_story.png&folder=comparemovies.png&folder=landevicefound.png&folder=it&folder=device-2015-08-19-005229.png&folder=bhakta.png&folder=Screenshot+from+2015-09-19+23%3A16%3A09.png&folder=arrow.png&folder=raghib_comment.png&folder=web_hi_res_512.png&folder=nfa_dfa.png&folder=raghiblul.png&folder=tux.png&folder=lexical.png&folder=likes.png&folder=raghib_lul.png&folder=bluegape.png&folder=con.png&folder=dfa_conversion.png&folder=bhakto+ko.png&folder=mynumber.png&folder=katjuJiReply.png&folder=tifY9AWf_400x400.jpg&folder=kalam.jpg&folder=bk.png&folder=1.png&folder=1_batman.png&folder=mealay.png
but output is only the last folder name.
Please help me to solve the problem.
try the form name name="folder[]" and then process in foreach folder

How to submit a form in footer part using codeigniter?

I am developing a website in Codeigniter . I have a contact form that is in footer. i want to submit that form. but i am not finding any idea in which controller should i submit this form.Is this will be done by using library or something else? Any help would be highly appreciated.
Form is.
<footer>
<div class="col-md-3 fst_follow">
<h3>Quick contact</h3>
<img class="foot_line" src="<?php echo base_url();?>images/foot_line.png" />
<div class="quick_form">
<form method="post">
<ul>
<li>
<input type="text" class="inputtxt" placeholder="name" /></li>
<li>
<input type="text" class="inputtxt" placeholder="Email*"/>
</li>
<li>
<textarea class="inputtxt" placeholder="Message*"></textarea>
</li>
<li>
<input type="submit" class="submit_btn" value="Submit" />
</li>
</ul>
</form>
</div>
</div>
</footer>
A Form can be submitted from anywhere in the page. It does not matter weather it is footer or main body.
Your project may contain controller like 'UserController' or 'FrontController' in which you can create a function that handles your form request.
Replace "YOUR_CONTROLLER" & "REQUESTED_METHOD" by your data in the following code. Change this to your Form Tag:
<form method="post" action="<?php echo base_url()."YOUR_CONTROLLER/REQUESTED_METHOD"; ?>" >

Cannot upload image using jquerymobile

I have a simple dialog box:
<div data-role="dialog" id="uploadImage" data-title="Upload Image" data-needs-auth="true">
<div data-role="header" data-position="fixed" data-theme="b">
<h1>Upload Image</h1>
</div><!-- /header -->
<div data-role="content">
<form name=uploadForm method=post enctype="multipart/form-data" action="uploadbi.php" data-ajax="false">
<input type=file name=filename>
<input type=hidden name=MAX_FILE_SIZE value=8000000>
<input type="submit" value="Upload Image" data-theme="a" data-inline="true">
</form>
</div>
</div>
</div>
The problem is that it does not pass the filename field. From Firebug:
Post Parameters
application/x-www-form-urlencoded
MAX_FILE_SIZE 8000000
seid 6e540f68067707233241eb170ca83c43
Source
MAX_FILE_SIZE=8000000&seid=6e540f68067707233241eb170ca83c43
This is running under Firefox and I verified that it also fails under Chrome. It's been forever since I've dealt with file uploads in a form. What am I missing?
Last month I had a similar problem. Try to add data-ajax="false" on your form definition and see if that will help.
For more information, you could check this link.

Submtting An animated form using jquery ajax and php to mysql database

I have been having problems for the past two days trying to submit a form using jquery ajax, php to mysql database. I reused a code for an animation form which I found online. The html code as follows (file name: "Slider.html"):
<html>
<body>
<div id="form_wrapper" class="form_wrapper">
<form class="register" style="right:-500px;backgroundcolor:grey;">
<h3>Register</h3>
<div class="column">
<div>
<label>First Name:</label>
<input type="text" />
<span class="error">This is an error</span>
</div>
<div>
<label>Last Name:</label>
<input type="text" />
<span class="error">This is an error</span>
</div>
</div>
<div class="column">
<div>
<label>Username:</label>
<input type="text"/>
<span class="error">This is an error</span>
</div>
<div>
<label>Email:</label>
<input type="text" />
<span class="error">This is an error</span>
</div>
<div>
<label>Password:</label>
<input type="password" id="r_passwordField"/>
<span class="error">This is an error</span>
</div>
</div>
<div class="bottom">
<div class="remember">
<input type="checkbox" />
<span>Send me updates</span>
</div>
<input type="submit" id="registrationform" value="register"/>
<a href="index.html" rel="login" class="linkform">You have an account already? Log in
here</a>
<div class="clear"></div>
</div>
</form>
<form class="login active">
<h3>Login</h3>
<div>
<label>Username:</label>
<input type="text" />
<span class="error">This is an error</span>
</div>
<div>
<label>Password: <a href="forgot_password.html" rel="forgot_password" class="forgot
linkform">Forgot your password?</a></label>
<input type="password" id="l_passwordField" size="10"/>
<span class="error">This is an error </span>
</div>
<div class="bottom">
<div class="remember"><input type="checkbox" /><span>Keep me logged in</span></div>
<input type="submit" id="loginform" value="Login"></input>
<a href="register.html" rel="register" class="linkform">You don't have an account yet?
Register here</a>
<div class="clear"></div>
</div>
</form> <form class="forgot_password">
<h3>Forgot Password</h3>
<div>
<label>Username or Email:</label>
<input type="text" />
<span class="error">This is an error</span>
</div>
<div class="bottom">
<input type="submit" id="forgortform" value="Send reminder"></input>
Suddenly remebered? Log in here
<a href="register.html" rel="register" class="linkform">You don't have an account?
Register here</a>
<div class="clear"></div>
</div>
</form>
</div>
<div id="graph-wrapper" class="graph-container" style="display:none">
<h3>Standard Diviation Bell Curve<h3>
<div class="graph-info">
Visitor
<span></span>
</div>
<div class="graph-container">
<div id="graph-lines"></div>
<div id="graph-bars"></div>
</div>
</div>
</div>
</body>
</html>
jquery ajax code as follows (jquery script on the same file as the html code):
<script>
$(document).ready(function(){
//animated code and other codes omitted
("#registrationform").click(function(){
$.post("postdata.php",
{fname:"Ibrahim",lname:"Ahmadu",email:"ibrostay#yahoo.com",uid:"ibro2stay",pwd:"ibro2stay",mean:"0.1",varience:"0.1",sdev:"0.
1",duration:"0.1"},function(responce){
if(responce==0){
alert("There was an error updating the record");
}else{
alert("update successful");
}
});
});
});
</script>
Below is the php code (php code file name: "postdata.php"):
<?php
$fname=$_REQUEST["fname"];
$lname=$_REQUEST["lname"];
$email=$_REQUEST["email"];
$uid=$_REQUEST["uid"];
$pwd=$_REQUEST["pwd"];
$mean=$_REQUEST["mean"];
$varience=$_REQUEST["varience"];
$sdev=$_REQUEST["sdev"];
$duration=$_REQUEST["duration"];
$con=mysql_connect('localhost','root','');
if(!$con)
{
die("Error Connecting to database;"+mysql_error());
}
$database=mysql_select_db('mydb');
if(!$database)
{
die("Error Connecting to database;"+mysql_error());
}
$update = mysql_query("insert into users values('$fname','$lname','$email','$uid','$pwd','$mean','$varience','$sdev','$duration')");
if(!$update)
{
die("Update wasn't Success full"+mysql_error());
}
echo "update successfull";
mysql_close($con);
?>
Whenever I click the register button nothing happens. The page only refreshes back to the login form since it has class "active" as the default form, and the browser address bar changes from this url: "localhost/slider.html" to this url: "localhost/slider.html?".
I hope my question was explicit enough, because I need an urgent answer, as this is my thesis project and I am running out of options.
and the browser address bar changes from this url: "localhost/slider.html" to this url: >"localhost/slider.html?".
use e.preventDefault();
$("#registrationform").click(function(e){
^
|
|_______________ you forgot the $
then add,
`e.preventDefault();
check javascript console and you will see all the errors. you have to eliminate one by one. For the start, check above.
advice: when you copy/paste codes, atleast try to know the structures. sometimes it wil conflict with your code and may stop running your code.
Looks like your Javascript has some errors and not executing hence. So, the form submit resorts to its default behavior - that is, submit to the tag's action attribute. Since you have not specified the action attribute in the tag, it will post the parameters to the current page.
You are getting the url localhost/slider.html? because of two reasons:
You have not specified method="post" in your . So, the form is trying to submit as GET. That is why the appended "?"
You do not have names for the inputs. So, the query string is empty. You need to specify name attribute for every input.
What you have to do first is to debug your Javascript. Use Firebug in Firefox or the console in Chrome or any similar tools to capture your JS errors and also examine your Ajax requests and responses.
Also, make sure that the last statement in the "click" function is a :
return false;
to force the form to stay on the page.
Another important thing is, as #steve pointed out, add method and action attributes to your tag. This will make sure that your script will not fail entirely on a JS disabled browser or on any such conditions.

Categories