[英]How to allow users to upload files to the website so that I can receive them?
I am getting a Server error when I am trying the following code on my localhost.当我在本地主机上尝试以下代码时出现服务器错误。 Please let me know if there's something wrong with my code
如果我的代码有问题,请告诉我
here's my HTML code:这是我的 HTML 代码:
<section class= "box3">
<h4>Become a contributor</h4>
<div class="lines"></div>
<form class="contact-form" action="uploads.php" method= "POST" enctype= "multipart/form-data">
<input type= "file" name="file" class= "contact-form-text" >
<button type="submit" class="contact-form-btn" name="submit">Upload</button>
</form>
</section>
Here's my PHP code这是我的 PHP 代码
<?php
if (isset($_POST['submit'])) {
$file = $_FILES ['file'];
$fileName = $_FILES ['file'] ['name'];
$fileTmpName = $_FILES ['file'] ['tmp_name'];
$fileSize = $_FILES ['file'] ['size'];
$fileError = $_FILES ['file'] ['error'];
$fileType = $_FILES ['file'] ['type'];
$fileExt = explode ('.',$fileName);
$fileActualExt = strtolower (end($fileExt));
$allowed = array ('jpg', 'jpeg', 'png', 'pdf', 'doc');
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 10000000) {
$fileNameNew = uniqid ('', true).".".$fileActualExt;
$fileDestination = 'upload/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
header ("Location : Contact.html?uploadedsuccessfully");
} else {
echo "Your file is too big!";
}
} else {
echo "There was an error uploading your file!";
}
} else {
echo "You cannot upload files of this type!";
}
}
this would work:这会起作用:
<?php
if (isset($_POST['submit'])) {
$file = $_FILES ['file'];
$fileName = $_FILES ['file'] ['name'];
$fileTmpName = $_FILES ['file'] ['tmp_name'];
$fileSize = $_FILES ['file'] ['size'];
$fileError = $_FILES ['file'] ['error'];
$fileType = $_FILES ['file'] ['type'];
$fileExt = explode ('.',$fileName);
$fileActualExt = strtolower (end($fileExt));
$allowed = array ('jpg', 'jpeg', 'png', 'pdf', 'doc');
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 10000000) {
$fileNameNew = uniqid ('', true).".".$fileActualExt;
$fileDestination = 'upload/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
header ("Location Contact.html uploadedsuccessfully");
} else {
echo "Your file is too big!";
}
} else { echo "There was an error uploading your file!"; }
} else { echo "You cannot upload files of this type!";}
}
?>
it seems the error was the question mark as below似乎错误是下面的问号
header ("Location Contact.html?uploadedsuccessfully");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.