这里我在php中创建了一个表单和操作文件,它完美无缺。然后我尝试在wordpress中实现它,表单显示良好,但当我提交它时,它不起作用。任何人都可以帮助我。
//here is my html form
<form action="<?php the_permalink(); ?>" method="post" enctype="multipart/form-data">
Please choose a file: <input type="file" name="uploadFile"><br>
<input type="submit" value="Upload File">
</form>
and here is action area
<?php
if(isset($_POST['submit'])) {
$target_dir = basename( $_FILES["uploadFile"]["name"]);
$uploadOk=1;
$contents2 = "";
if (move_uploaded_file($_FILES["uploadFile"]["tmp_name"], $target_dir)) {
echo "The file ". basename( $_FILES["uploadFile"]["name"]). " has been uploaded.";
$CSVfp = fopen($target_dir, "r");
if($CSVfp !== FALSE)
while(!feof($CSVfp)) {
$data = fgetcsv($CSVfp, 3000, ",");
$contents2 .= $data[3];
$var_str = var_export($contents2, true);
$file = 'new_file.txt';
$var_str = str_replace("'",",",$var_str);
$var_str3 = ltrim($var_str,"Pin,");
$var_str3 = implode(",", str_split($var_str3, 6))." ";
$var_str4 = str_replace(",,","",$var_str3);
file_put_contents($file, $var_str4);
}
}
else {
echo "Sorry, there was an error uploading your file.";
}
?>
<form method="get" action="new_file.txt">
<button type="submit">Download!</button>
</form>
<?php
}
?>