douliao5550 2015-05-30 18:46
浏览 86
已采纳

图片上传png / jpg

I have a problem with uploading images from a SSL secure web page to the server, the image uploads correctly but doesn't come in the selected path.

<?php
    if($_SERVER['REQUEST_METHOD'] == 'POST') {
        $errors = Array();
        if(isset($_POST['title'])) {
            if(trim($_POST['title']) != '') {
                if(strlen(trim($_POST['title'])) < 2) {
                    $errors[] = 'De titel is te kort (2).';
                }
            }else{
                $errors[] = 'De titel is leeg gelaten.';
            }
        }else{
            $errors[] = 'Er is geen titel meegestuurd.';
        }

        if(isset($_POST['category'])) {
            if(trim($_POST['category']) != '') {
                if(!in_array(trim($_POST['category']), array_flip($config['general']['cat']))) {
                    $errors[] = 'Deze catagorie bestaat niet!';
                }
            }else{
                $errors[] = 'Catagorie is leeg gelaten.';
            }
        }else{
            $errors[] = 'Er is geen catagorie meegestuurd.';
        }   

        if(isset($_POST['graad'])) {
            if(trim($_POST['graad']) != '') {
                if(!in_array(trim($_POST['graad']), array_flip($config['general']['graad']))) {
                    $errors[] = 'Deze moeilijksheidgraad bestaat niet!';
                }
            }else{
                $errors[] = 'Moeilijkheidsgraad is leeg gelaten.';
            }
        }else{
            $errors[] = 'Er is geen moeilijksheidgraad meegestuurd.';
        }   

        if(isset($_POST['description'])) {
            if(trim($_POST['description']) != '') {
                if(strlen(trim($_POST['description'])) < 5) {
                    $errors[] = 'De bereidingstekst is te kort (5).';
                }
            }else{
                $errors[] = 'De bereidingstekst is leeg gelaten.';
            }
        }else{
            $errors[] = 'Er is geen bereidingstekst meegestuurd.';
        }   

        if(isset($_FILES['photo'])) {
            if($_FILES['photo']['type'] != '') {
                if($_FILES['photo']['type'] != 'image/jpeg') {
                    $errors[] = 'Uw foto is geen JPG afbeelding.';
                }
            }
        }

        if(isset($_POST['time'])) {
            if(trim($_POST['time']) != '') {
                if(strlen(trim($_POST['time'])) < 1) {
                    $errors[] = 'De bereidingstijd is te kort (5).';
                }
            }else{
                $errors[] = 'De bereidingstijd is leeg gelaten.';
            }
        }else{
            $errors[] = 'Er is geen bereidingstijd meegestuurd.';
        }                                   

        if(count($errors) == 0) {
            $title = trim($_POST['title']);
            $category = trim($_POST['category']);
            $graad = trim($_POST['graad']);
            $description = trim($_POST['description']);
            $time = trim($_POST['time']);
            $update = $dbh->prepare('UPDATE recettes SET title = :title, category = :category, graad = :graad, description = :description, time = :time WHERE id = :id');
            $update->bindParam(':title', $title, PDO::PARAM_STR);
            $update->bindParam(':category', $category, PDO::PARAM_STR);
            $update->bindParam(':graad', $graad, PDO::PARAM_STR);
            $update->bindParam(':description', $description, PDO::PARAM_STR);
            $update->bindParam(':time', $time, PDO::PARAM_STR);
            $update->bindParam(':id', $_GET['id'], PDO::PARAM_INT);
            $update->execute();
            if(isset($_FILES['photo']) && $_FILES['photo']['type'] != '') {
                if(file_exists('/home/joshua3/domains/recettes.nl/public_html/uploads/photo-' . $uid . '.jpg')) {
                    unlink('/home/joshua3/domains/recettes.nl/public_html/uploads/photo-' . $uid . '.jpg');
                }
                move_uploaded_file($_FILES['photo']['tmp_name'], '/home/joshua3/domains/recettes.nl/public_html/uploads/photo-' . $uid . '.jpg');
            }
            echo '<font color="green">De instellingen zijn succesvol opgeslagen</font><meta http-equiv="refresh" content="1;url=https://www.recettes.nl/edit/' .$_GET['id']. '">';
            $edited = true;
        }else{
            echo 'Er ging wat mis. De volgende dingen gingen fout:<ul><li>' . join('</li><li>', $errors) . '</li></ul>De instellingen zijn niet opgeslagen, probeer het opnieuw.';
        }
    }
    if(!isset($edited)) {
?>

The problem was solved once but after editing and changing server, the problem came back.

<div class="grid desk-12 both">
<div class="form-label">Afbeelding<font color="red">**</font></div>
<div class="form-description">Wij ondersteunen alle afbeelding formaten. Wij accepteren alleen .jpg formaat.</div>
<input type="file" name="photo" multiple="multiple" class="multi with-preview">
</div>

This below is the head of the form >

<form action="" method="post" enctype="multipart/form-data">

The map 'uploads' is already chmod 777.

Can you please assist me to solve this issue.

  • 写回答

1条回答 默认 最新

  • duanlinghe8417 2015-05-30 18:51
    关注
    <form action="" method="post" enctype="multipart/form-data">
    

    is started after your input, place your input inside the form tag.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog