I am trying to debug the code since 2 hours, but cannot find the issue here. This code is not uploading any files! also it doesnt show any error. seems like the server is not receiving the file at all!
here is the html part
<form action="?" method="post" enctype="multipart/form-data" name="form1" id="form1">
<label>Select file: (Max size: 2mb)</label>
<input type="file" name="xls_file" id="xls_file" /> <input type='hidden' value='55' name='yo' />
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
here is the PHP part
if(isset($_FILES['xls_file'])) {
if ($_FILES['xls_file']['error'] !== UPLOAD_ERR_OK) {
die("Upload failed with error code " . $_FILES['xls_file']['error']);
}}
if(isset($_FILES['xls_file'])){
$file_name = $_FILES['xls_file']['name'];
$allowed = array('xls','xlsx','csv');
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
$file_size =$_FILES['xls_file']['size'];
$file_tmp =$_FILES['xls_file']['tmp_name'];
$file_type=$_FILES['xls_file']['type'];
//check for valid file
if(!in_array($ext,$allowed)) {
echo "Invalid file type.";
exit;
}
//check for file size
if(($file_size/1000) > 2100){
echo "File size greater than allowed limit. Kindly choose a small file. ";
exit;
}
move_uploaded_file($file_tmp,"./".str_replace(array('"',"'","\\","=","<",">","`",";"), '', $file_name));
$uploaded = true;
}
here is the complete code
<?php
$G_POST = str_replace(array('"',"'","\\","=","<",">","`",";"), '', $_POST);
$G_GET = str_replace(array('"',"'","\\","=","<",">","`",";"), '', $_GET);
if($G_POST[filename])
$uploaded = true;
if(isset($_FILES['xls_file'])) {
if ($_FILES['xls_file']['error'] !== UPLOAD_ERR_OK) {
die("Upload failed with error code " . $_FILES['xls_file']['error']);
}}
if(isset($_FILES['xls_file'])){
$file_name = $_FILES['xls_file']['name'];
$allowed = array('xls','xlsx','csv');
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
$file_size =$_FILES['xls_file']['size'];
$file_tmp =$_FILES['xls_file']['tmp_name'];
$file_type=$_FILES['xls_file']['type'];
//check for valid file
if(!in_array($ext,$allowed)) {
echo "Invalid file type.";
exit;
}
//check for file size
if(($file_size/1000) > 2100){
echo "File size greater than allowed limit. Kindly choose a small file. ";
exit;
}
move_uploaded_file($file_tmp,"./".str_replace(array('"',"'","\\","=","<",">","`",";"), '', $file_name));
$uploaded = true;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Excel (xls,xlsx,csv) to VCF (vCard) Online Converter - The Web Vendor</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="main" class="ui-content">
<?php
//STEP 1, ON LOAD
if(!$uploaded) {
?>
<h2>Excel to VCF Converter</h2>
<p>This is a simple, 3-step tool to convert your contact details in excel / spreadsheet to vCard (3.0) format. Supported formats are: xls, xlsx and csv.</p>
<p>Must Watch video tutorial here: <a href="https://www.youtube.com/watch?v=sn7ROzt9YRA" target="_blank">https://www.youtube.com/watch?v=sn7ROzt9YRA</a></p>
<hr/>
<h3>Step 1:</h3>
<form action="?" method="post" enctype="multipart/form-data" name="form1" id="form1">
<label>Select file: (Max size: 2mb)</label>
<input type="file" name="xls_file" id="xls_file" /> <input type='hidden' value='55' name='yo' />
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
<?php }
//STEP 2, AFTER FILE UPLOAD
else if(!$G_POST[filename]) {
?>
<form action="?" method="post" name="step2">
<h3>Step 2:</h3>
<label>Uploaded file:</label>
<input type="text" name="filename" id="filename" readonly="readonly" value="<?php echo str_replace(array('"',"'","\\","=","<",">","`",";"), '', $file_name) ?>" />
<label>Sheet no: </label>
<input name="sheet" type="number" required="required" id="sheet" max="9999" min="1" value="1" />
<label>First Column:</label>
<select name="first_column" id="first_column" required >
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
<option value="F">F</option>
<option value="G">G</option>
<option value="H">H</option>
<option value="I">I</option>
<option value="J">J</option>
<option value="K">K</option>
<option value="L">L</option>
<option value="M">M</option>
</select>
<label>Last Column:</label>
<select name="last_column" id="last_column" required >
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
<option value="F">F</option>
<option value="G">G</option>
<option value="H">H</option>
<option value="I">I</option>
<option value="J">J</option>
<option value="K">K</option>
<option value="L">L</option>
<option value="M">M</option>
<option value="N">N</option>
</select>
<label>First Row:</label>
<input type="number" name="first_row" id="first_row" min="1" max="9999" required="required" />
<label>Last Row:</label>
<input type="number" name="last_row" id="last_row" min="1" max="9999" required="required" />
<input type="submit" value="Submit">
</form>
<?php
}
?>
</div>
</div>
</body>
</html>
I am experienced. but never experienced any such issue.