duanpao6163 2015-01-20 10:50
浏览 34
已采纳

使用PHP进行jQtouch / Contao图像上传

I am trying to upload images with a form to my webserver but the $_FILES['file'] can't find my file.

Its designed only for mobiles and I'm using Contao as CMS. I can upload with files on the server if I use a new Page that wasn't generated by Contao or jQtouch. The code down is implemented in my CMS. I think there are problems with jQuery or Ajax. Is there a way I can make it work?

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");
}

I just started programming some weeks ago and I'm really new to web development so it would help me if you'd post finished code how to fix it or a detailed instruction.

  • 写回答

2条回答 默认 最新

  • douyan1921 2015-01-20 10:58
    关注

    1) your code has if(isset($_POST['file'])){ in PHP and in your HTML name of the control is filetoUpload <input type="file" name="fileToUpload" id="fileToUpload">

    match the names and you should be through. 2) <li><a name="submit" value="Upload" type="submit" style="margin-top: 10px; margin-bottom: 10px;" href="#" class="submit whiteButton">Senden</a> If I remember correctly, <a> tag is never of type submit , it is always input type="submit" or if you want to submit the form , remove type="submit" from your code and instead use this code

    <li><a name="submit" value="Upload" onclick="document.forms[0].submit();" style="margin-top: 10px; margin-bottom: 10px;" href="#" class="submit whiteButton">Senden</a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法