我在php中做一个简单的文件格式,它适用于safari,mozilla(mac& pc)chrome(mac& pc)而不是IE8,我的$ _FILES是真的!。
标题:
<?php
session_start();
header('P3P: CP="NON DSP TAIa PSAa PSDa OUR IND UNI", policyref="/w3c/p3p.xml"');
header('P3P: CP="CAO PSA OUR"');
?>
<!DOCTYPE html>
<html>
<head>
<title>mcp</title>
<meta name="apple-mobile-web-app-capable" content="no">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=IE8">
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta http-equiv="Content-type" content="text/html;charset=utf-8" />
<!-- CSS -->
<link rel="stylesheet/less" type="text/css" href="../styles/design.less"/>
<link rel="stylesheet/less" type="text/css" href="../styles/style.css"/>
<!--JS -->
<script src="../js/less.min.js"></script>
<script src="../js/jquery-1.9.1.min.js"></script>
<script src="../js/parsley.js"></script>
</head>
<body>
<div id="header-pic">
<img src="../styles/img/header_pic.png" alt="header-pic" />
</div>
<div id="mpcp">
<img src="../styles/img/mpcp.png" alt="mpcp" />
</div>
我的表格在那里:
<form action="thanks.php" method="post" data-validate="parsley" enctype="multipart/form-data">
<label for="input-firstname">First name</label>
<input data-required="true" type="text" class="text" id="input-name-field" name="firstname"/><br>
<label for="input-lastname">Last name</label>
<input data-required="true" type="text" class="text" id="input-surname-field" name="lastname"/><br>
<label for="input-mail">e-mail</label>
<input data-type="email" data-required="true" type="text" class="text" id="input-mail-field" name="email"/><br>
<label for="input-picture">Picture</label>
<input type="button" id="clickme" value="Browse" />
<input type="text" id="filename" />
<input type="file" name="file" id="uploadme" />
<input id="validate" type="submit" value="VALIDATE">
</form>
处理文件代码在那里:
if (isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['email']) && isset($_FILES["file"]) && $_FILES["file"]["name"] != '') {
$_SESSION['firstname'] = $_POST['firstname'];
$_SESSION['lastname'] = $_POST['lastname'];
$_SESSION['email'] = $_POST['email'];
$_SESSION['photo'] = $_POST['firstname'].'-'.$_POST['lastname'];
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
$_SESSION['photo'] = $_POST['firstname'].'-'.$_POST['lastname'].'.'.$extension;
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") ||
($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") ||
($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 1000000) && in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
$error = $_FILES["file"]["error"];
} else {
$_FILES["file"]["name"] = $_POST['firstname'].'-'.$_POST['lastname'];
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("../upload/" . $_FILES["file"]["name"])){
unlink("../upload/" . $_FILES["file"]["name"]);
}
$res = move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" . $_FILES["file"]["name"].'.'.$extension);
if ($res == true) {
echo "Stored in: " . "../upload/" . $_FILES["file"]["name"];
} else {
$error = "Invalid file";
}
}
} else {
$error = "Invalid file";
}
} else {
header("Location: reglement.php");
}
我要打我的电脑因为它总是去标题(“Location:reglement.php”); 谢谢你的帮助!