上传图片期间var_dump($ _ FILES)没有错误,但图片没有上传

时间:2014-11-02 21:27:06

标签: php image image-uploading

我有.php用于上传图片,现在当我想上传图片multipart / form-data .php时重新加载而不更新图片。 这是var_dump($ _ FILES)

的输出
 array(1) 
{ ["slika"]=> array(5) { 
["name"]=> string(8) "test.png" 
["type"]=> string(9) "image/png" 
["tmp_name"]=> string(14) "/tmp/phpe46Qae" 
["error"]=> int(0) 
["size"]=> int(22970) } }

没有显示错误,但未上传图片。 的修改

This is hole php
form method="POST" action="" name="form" id="form" enctype="multipart/form-data">

<label>Add your photo to the gallery</label><br>
<textarea name="opiss" placeholder="Description" style="margin: 2px; height: 150px; width: 238px;"></textarea><br>
<input name="slika" id="slika" type="file" style="width: 238px;" /><br>
<input type="checkbox" id="frienduh" name="frienduh" value="1"/> Check it.<br>
<span style='color: white;
padding-top: 6px;
font-size: 10px;
float: left;'>
    By clicking this your photo will become public!
</span><br><br>
<input type="submit" id="lodd" value="Add" class="button" name="dodaj" />

</form>




<?php

if (isset($_REQUEST['dodaj'])) {



    $opis=mysqli_real_escape_string($conn,$_REQUEST['opiss']);


function died($error) { 
            $poruka = "We are sorry, but there was a problem with upload.\n\nErrors:\n$error\nPlease correct the error and try again.";
            ?>
            <script> alert(<?php echo json_encode($poruka); ?>); setTimeout(function() {window.history.go(-1)}, 500); </script>;  
            <?php

            die(); 
        }
    if($_FILES['slika']['size'] < 10485760){




                $opis = mysqli_real_escape_string($conn, $_POST['opiss']);
                if(strlen($opis)>301){
        died('You can enter up to 30 characters in the description field.');
    }
                $validExtensions = array('.jpg','.JPG','.jpeg','.JPEG','.png','.PNG','.gif','.GIF');
                $fileExtension = strrchr($_FILES['slika']['name'], '.');
                 if (in_array($fileExtension, $validExtensions)) {

                $newNamePrefix = time() . '_';
                            $manipulator = new ImageManipulator($_FILES['slika']['tmp_name']);
                            // resizing to 200x200
                            $newImage3 = $manipulator->resample(800, 600);
                            // saving file to uploads folder
                            $manipulator->save('galerija/'.$newNamePrefix.$_FILES['slika']['name']);

                            if (isset($_POST['frienduh'])){
                                $frienduh=1;
                                }else{
                                $frienduh=0;
                            }


                    $upis=mysqli_query($conn,"INSERT INTO galerija VALUES(null,".$_SESSION['group_id'].",'".$opis."','".$newNamePrefix.$_FILES["slika"]["name"]."',0,".$frienduh.",0,0)") or die(mysqli_error($conn));



                            if (isset($_POST['frienduh'])){
                                $gal=mysqli_query($conn,"SELECT id_gal from galerija where putanja_slike='".$newNamePrefix.$_FILES["slika"]["name"]."'");
                                $gal_id=mysqli_fetch_array($gal,MYSQL_ASSOC);
                                $upis2=mysqli_query($conn,"INSERT INTO main_board (id_gal,group_id,doing,content) values(".$gal_id['id_gal'].", ".$_SESSION['group_id'].", 'want to check', '<br><a href=\'/friendornot/photo/".$gal_id['id_gal']."\' title=\'".$opis."\' ><img style=\'max-width:350px;max-height:250px;\' src=\'/galerija/".$newNamePrefix.$_FILES["slika"]["name"]."\'/></a>' )") or die(mysqli_error($conn));
                            }





                }else{
                    died('File type not allowed!');
                }


    }else{
        died('File size must be less than 5MB.');
    }

}

停止工作大约一两个星期。这不是我之前的开发人员留下的代码。我不能很好地回答为什么这个上传停止工作。

修改

更新Debian 7和php后,.php问题启动没问题。这个.php在localhost和其他服务器上工作。如果我发现它我将发布,我没有为此解决这个问题。文件夹galerija也有所有permision,并在php.ini evrithing是好的

memory_limit = 128M
post_max_size = 12M
file_uploads = On
upload_max_filesize = 12M

2 个答案:

答案 0 :(得分:0)

您必须手动上传它们。 在这里阅读更多内容:

http://php.net/manual/bg/function.move-uploaded-file.php

答案 1 :(得分:0)

更新Debian Wheezy后出现问题。

  

PHP警告:mysqli :: mysqli():标头和客户端库次要   版本不匹配。

所以这对我有帮助,也许对其他人有帮助。

  

apt-get install php5-mysqlnd

安装图片上传后再正常工作。