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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀