2015-03-03 45 views
0

我想使用getimagesize函数。我正在使用Dropzone.js进行图片上传,并使用codeigniter。getimagesize()不返回图像值

上传功能:

public function upload() //upload multiple images-dropzone 

{ 
     if (!empty($_FILES)) { 
     $tempFile = $_FILES['file']['tmp_name']; 

    $fileName = str_replace(' ', '_', $_FILES["file"]["name"]); 
    $file_name = substr(uniqid(rand()),0,10000).'_'.$fileName ; 
     $targetPath = './uploads/'; 
     $targetFile = $targetPath . $file_name ; 
     move_uploaded_file($tempFile, $targetFile); 



    $this->thumb($targetFile,$targetPath,$file_name,$tempFile);  

}} 

我的拇指功能:

function thumb($targetFile,$targetPath,$file_name,$tempFile) 
{ 
    require_once('php_image_magician.php'); 

    $magicianObj = new imageLib($targetFile); 

    list($width, $height, $type, $attr) = getimagesize($tempFile); 

    if($width = $height) 
    { 
    $magicianObj->resizeImage(150,150); 
    } 
    else if($width > $height) 
    { 
    $magicianObj->resizeImage(150,40); 
    } 
    else 
    { 
    $magicianObj->resizeImage(40,150); 
    } 


    // saving file to thumb directory 
    $magicianObj->saveImage($targetPath . 'thumb/' . $file_name, 100); 
} 

在这种情况下,我想比较的高度和宽度,但它不能正常工作。它始终是第一个条件。

+0

检查该路径上是否存在图像,如果存在,则检查文件所需的权限。 – 2015-03-03 12:05:27

+0

您正在为第一个条件赋值,您需要使用比较运算符'=='另外Codeigniter也有自己的上传/图像处理库。 – Philip 2015-03-03 12:11:12

+0

我改变它==,但它仍然无法正常工作。 – 2015-03-03 12:18:55

回答

0

你已经使用了move_uploaded_file,所以在$ tempFile之后就不会找到它,因为它已经被移动了,而是使用copy()函数。

+0

copy($ tempFile,$ temp);不工作 – 2015-03-03 12:27:28

+0

你做了拷贝($ tempFile,$ targetFile)吗? – 2015-03-03 12:28:51

+0

为什么复制$ tempfile到$ targetFile? – 2015-03-03 12:39:59