移动上传的文件在PHP中不起作用

时间:2018-08-02 20:03:36

标签: php

我正在使用PHP脚本来调整上传图像的大小。它工作正常,但我想将已调整大小的上载图像移动到特定目录中,但我无法正常工作。谁能告诉我我错了吗?

谢谢。

<?php
    $name = ''; $type = ''; $size = ''; $error = '';
    function compress_image($source_url, $destination_url, $quality) {

        $info = getimagesize($source_url);

            if ($info['mime'] == 'image/jpeg')
                    $image = imagecreatefromjpeg($source_url);

            elseif ($info['mime'] == 'image/gif')
                    $image = imagecreatefromgif($source_url);

        elseif ($info['mime'] == 'image/png')
                    $image = imagecreatefrompng($source_url);

            imagejpeg($image, $destination_url, $quality);
        return $destination_url;
    }

    if ($_POST) {

            if ($_FILES["file"]["error"] > 0) {
                    $error = $_FILES["file"]["error"];
            } 
            else if (($_FILES["file"]["type"] == "image/gif") || 
            ($_FILES["file"]["type"] == "image/jpeg") || 
            ($_FILES["file"]["type"] == "image/png") || 
            ($_FILES["file"]["type"] == "image/pjpeg")) {

                    $url = "mypic.jpg";

                    $filename = compress_image($_FILES["file"]["tmp_name"], $url, 80);

                   //This is where the script stops working
  if (move_uploaded_file($filename, "myFolder/".$url)) {
echo "Completed"
 }else{
     $error = "Uploaded image should be jpg or gif or png";
    echo $error;
 }


            }
  }
?>

0 个答案:

没有答案