我想添加一個圖片上傳字段到我的PHP聯繫表格。我有contact.html其中發佈到contact.php。我將所有數據寫入errors.txt文件。用PHP上傳圖片到.txt文件
我希望能夠將圖像上傳到服務器上的「上傳」文件夾,同時將其註冊到errors.txt文件中。
我已標記上傳的部分與工作評論。請指導我。
contact.html
<html>
<head>
</head>
<body>
<form name="form1" method="post" enctype="multipart/form-data" action="contact.php">
<h1>Basic Info</h1>
Username: <input type="text" name="user">
<br>Email: <input type="text" name="mail">
<option value="intermediate">Intermediate</option> <option value="advanced">Advanced</optio></select>
<!-- Image Upload Code - NOT WORKING -->
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<br> <input type="submit" name="submit" value="submit">
</form>
</body>
</html>
contact.php
<?php
if(isset($_POST['submit']))
{
$username = $_POST['user'];
$email = $_POST['mail'];
$experience = $_POST['exp'];
// IMAGE UPLOAD CODE - NOT WORKING
$target_file = "uploads/" . basename ($_FILES["fileToUpload"]["name"]);
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
//the data
$data = "$username | $email | $experience | $target_file\n";
//open the file and choose the mode
$fh = fopen("errors.txt", "a");
fwrite($fh, $data);
//close the file
fclose($fh);
print "User Submitted";
}
?>
'action =「signup.php」'好像是提交到另一個腳本。 – 2014-11-06 16:37:10
好趕時間timothy – 2014-11-06 16:41:19
@TimothyHa - 這是我在發佈時在這裏發佈的類型。原來的問題仍然存在。 – toiteam 2014-11-06 16:41:41