我正在尝试将带有表单的图像上传到我的网络服务器,但 $_FILES['file'] 找不到我的文件。
它只为手机设计,我使用 Contao 作为 CMS。如果我使用不是由 Contao 或 jQtouch 生成的新页面,我可以在服务器上上传文件。下面的代码是在我的 CMS 中实现的。我认为 jQuery 或 Ajax 存在问题。有没有办法让它工作?
HTML:
<form action="/send_mail_php.php" method="post" enctype="multipart/form-data">
<ul class="edit rounded">
<li class="arrow">
<select id="Anrede">
<option value="Frau">Frau</option>
<option value="Herr">Herr</option>
</select>
</li>
<li>
<input type="text" name="Firma" placeholder="Firma*" id="firma" data-emoji_font="true" style="font-family: 'Avenir Next', Avenir, 'Segoe UI Emoji', 'Segoe UI Symbol', Symbola, EmojiSymbols !important;">
</li>
<li>
<input type="text" name="Abteilung" placeholder="Abteilung*" id="abteilung" data-emoji_font="true" style="font-family: 'Avenir Next', Avenir, 'Segoe UI Emoji', 'Segoe UI Symbol', Symbola, EmojiSymbols !important;"/>
</li>
<li>
<input type="text" name="Vorname" placeholder="Vorname*" id="vorname" data-emoji_font="true" style="font-family: 'Avenir Next', Avenir, 'Segoe UI Emoji', 'Segoe UI Symbol', Symbola, EmojiSymbols !important;"/>
</li>
<li>
<input type="text" name="Nachname" placeholder="Nachname*" id="nachname" data-emoji_font="true" style="font-family: 'Avenir Next', Avenir, 'Segoe UI Emoji', 'Segoe UI Symbol', Symbola, EmojiSymbols !important;">
</li>
<li>
<input type="tel" name="Telefon" placeholder="Telefon*" id="telefon">
</li>
<li>
<input type="email" name="Email" placeholder="E-Mail-Adresse*" id="email">
</li>
<li>
<input type="text" name="Ort" placeholder="Wo ist der Schaden?*" id="ort" data-emoji_font="true" style="font-family: 'Avenir Next', Avenir, 'Segoe UI Emoji', 'Segoe UI Symbol', Symbola, EmojiSymbols !important;">
</li>
<li>
<input type="file" name="fileToUpload" id="fileToUpload">
<li>
<textarea name="Schadensbericht" placeholder="Schadensbericht*" id="bericht" data-emoji_font="true" style="font-family: 'Avenir Next', Avenir, 'Segoe UI Emoji', 'Segoe UI Symbol', Symbola, EmojiSymbols !important;"></textarea>
</li>
<li>
Kopie an mich
<input name="checkbox" id="checkbox" type="checkbox" class="toggle">
</li>
<li>
<a name="submit" value="Upload" type="submit" style="margin-top: 10px; margin-bottom: 10px;" href="#" class="submit whiteButton">Senden</a>
</li>
</ul>
</form>
PHP:
if(isset($_POST['fileToUpload'])){
$src = $_FILES['fileToUpload']['tmp_name'];
$dst = $target_path;
if (!file_exists($src))
echo ("<br>File wasn't found<br> SRC = ".$_REQUEST['file']);
if (!is_readable($src))
echo ("<br>File is uploaded but not readable");
if (!is_writeable($destination_path))
echo ("<br>Check your permission for the destination directory");
@touch($dst);
if (!file_exists($dst))
echo ("<br>Error (?)");
if (@move_uploaded_file($_FILES['fileToUpload']['tmp_name'], "images/".$_FILES['fileToUpload']["name"])) {
$checkUpload = 'true';
}
else {
$checkUpload = 'false';
}
}
else {
echo ("<br>Error: Not working");
}
我几周前才开始编程,我对 Web 开发真的很陌生,所以如果你发布完成的代码如何修复它或详细的说明,这将对我有所帮助。