-1
をシリアライズ私のHTMLPHPファイルは、Ajaxにアップロードしていない。ここ
<form class="form form-vertical captcha_from" style="width: 50%;" method="post" action="<?php echo base_url('home/post_job_save'); ?>" enctype = "multipart/form-data">
<div class="container">
<div class="row form-group">
<div class="col-xs-12">
<ul class="nav nav-pills nav-justified thumbnail setup-panel">
<li class=""><a href="#step-1">
<h4 class="list-group-item-heading">Add Profile</h4>
<p class="list-group-item-text">First Step</p>
</a></li>
<li class=""><a href="#step-2">
<h4 class="list-group-item-heading">Add Resume</h4>
<p class="list-group-item-text">Second Step</p>
</a></li>
<li class=""><a href="#step-3">
<h4 class="list-group-item-heading">Add Cover Letter</h4>
<p class="list-group-item-text">Third Step</p>
</a></li>
<li class="active"><a href="#step-4">
<h4 class="list-group-item-heading">Add Photo</h4>
<p class="list-group-item-text">Fourth Step</p>
</a></li>
</ul>
</div>
</div>
<div class="row setup-content" id="step-1" >
<div class="col-xs-12">
<div class="col-md-12 well">
<h1>Add Profile</h1>
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<div class="control-group">
<label>First Name*</label>
<div class="controls">
<input type="text" class="form-control" placeholder="First Name" name="first_name" required="">
</div>
</div>
<div class="control-group">
<label>Last Name*</label>
<div class="controls">
<input type="text" class="form-control" placeholder="last Name" name="last_name" required="">
</div>
</div>
<div class="control-group">
<label>Email*</label>
<div class="controls">
<input type="email" class="form-control" placeholder="Email" name="email" required="">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row setup-content" id="step-2">
<div class="col-xs-12">
<div class="col-md-12 well">
<h1 class="text-center">Add Resume</h1>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label for="file">Select a file to upload</label>
<input type="file" name="resume">
<p class="help-block">Only jpg,jpeg,png and gif file with maximum size of 1 MB is allowed.</p>
</div>
</div>
</div>
</div><!-- /container -->
</div>
</div>
</div>
<div class="row setup-content" id="step-3">
<div class="col-xs-12">
<div class="col-md-12 well">
<h1 class="text-center">Add Cover Letter</h1>
<div class="form-group">
<label for="file">Select a file to upload</label>
<input type="file" name="cover_letter">
<p class="help-block">Only jpg,jpeg,png and gif file with maximum size of 1 MB is allowed.</p>
</div>
</div>
</div>
</div>
<div class="row setup-content" id="step-4">
<div class="col-xs-12">
<div class="col-md-12 well">
<h1 class="text-center">Add Photo</h1>
<div class="form-group">
<label for="file">Select a file to upload</label>
<input type="file" name="photo">
<p class="help-block">Only jpg,jpeg,png and gif file with maximum size of 1 MB is allowed.</p>
</div>
<input type="submit" id="apply_job_save_submit" class="btn btn-primary btn-md" value="Submit">
</div>
</div>
</div>
</div></form>
のJsコード
$('#apply_job_save_submit').on('click', function(e) {
$.ajax({
type: 'post',
url: base_url+'jobs/home/apply_job_save',
data: $('#apply_job_save').serialize(),
success: function() {
document.getElementById('createarea').innerHTML = "SUCCESS";
}
});
});
PHPコードです:このコードを使用して
if(isset($_FILES) && $_FILES["resume"]["name"]!=''){
$org_filename=$_FILES["resume"]["name"];
$arr=explode('.', $org_filename);
$filename='resume'.time().'.'.$arr[count($arr)-1];
$target_dir = UPLOAD_PATH;
$target_file = $target_dir . basename($filename);
move_uploaded_file($_FILES["resume"]["tmp_name"], $target_file);
$_POST['resume']=$filename;
}
if(isset($_FILES) && $_FILES["cover_letter"]["name"]!=''){
$org_filename=$_FILES["cover_letter"]["name"];
$arr=explode('.', $org_filename);
$filename='cover_letter'.time().'.'.$arr[count($arr)-1];
$target_dir = UPLOAD_PATH;
$target_file = $target_dir . basename($filename);
move_uploaded_file($_FILES["cover_letter"]["tmp_name"], $target_file);
$_POST['cover_letter']=$filename;
}
if(isset($_FILES) && $_FILES["photo"]["name"]!=''){
$org_filename=$_FILES["photo"]["name"];
$arr=explode('.', $org_filename);
$filename='photo'.time().'.'.$arr[count($arr)-1];
$target_dir = UPLOAD_PATH;
$target_file = $target_dir . basename($filename);
move_uploaded_file($_FILES["photo"]["tmp_name"], $target_file);
$_POST['photo']=$filename;
}
$this->general_model->insert('apply_job',$_POST);
私はにいくつかのデータを送信しよう私のデータベースだけでなく、postメソッドを使用して私のサーバーにファイルをアップロードします。すべてのデータは正常に掲載されましたが、ファイルはアップロードされません。 cover_letter 未定義のインデックス: 未定義のインデックスを再開する:写真 はこの
オンラインで入手できるajax経由でファイルをアップロードする方法の例は、数百ではないにしても数多くあります。それらのいずれかをチェックしましたか?そうした場合、クライアント側でいくつかのコードと設定を追加して動作させる必要があることがかなりわかります。 – ADyson