问:当我执行这个file.php时,它只会上传,而当我在Mainlayout.php中运行时,它不会上传。下面的文件是File.php,它可以上传csv文件。可以帮助我plzzzzzzzz
<form name="import" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
include ("connection1.php");
if (isset(_POST["submit"])) {
$file = _FILES['file']['tmp_name'];
$handle = fopen($file, "r");
$c = 0;
while (($filesop = fgetcsv($handle, 1000, ",")) !== false) {
$contact = $filesop[0];
if (preg_match('/(7|8|9)\d{9}/', $contact)) { // phone number is valid
$sql = mysql_query("INSERT INTO csv1 (contact) VALUES ('$contact')");
$c = $c + 1;
}
}
if ($sql) {
echo "Your Database Has Imported Successfully. You have Inserted " . $c . " Records";
} else {
echo "Sorry! There is a Some Problem.";
}
}
?>
</div>
</body>
答:您的代码看起来失真,请仅在pre(代码)标记之间提供您的代码,请勿在代码中添加任何多余的样式。例如-
<pre>代码</ pre>