Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么imagejpeg不';不创建缩略图?_Php_Html_File Upload - Fatal编程技术网

Php 为什么imagejpeg不';不创建缩略图?

Php 为什么imagejpeg不';不创建缩略图?,php,html,file-upload,Php,Html,File Upload,我有一个上传图片的小表单和它背后的php脚本: <?php $ds = DIRECTORY_SEPARATOR; $storeFolder = '../../../images/gallery/pictures'; $allowedExtensions = array ('image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png'); if

我有一个上传图片的小表单和它背后的php脚本:

<?php
$ds          = DIRECTORY_SEPARATOR;
$storeFolder = '../../../images/gallery/pictures';
$allowedExtensions = array ('image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png');

if (!empty($_FILES)) {

    if (in_array($_FILES['file']['type'], $allowedExtensions)) {

        $tempFile = $_FILES['file']['tmp_name']; 
        $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
        $targetFile =  $targetPath. $_FILES['file']['name']; 

        if (move_uploaded_file($tempFile, $targetFile)) {

            $image = imagescreatefromjpeg($storeFolder. $ds .$_FILES['file']['name']);
            $width  = imagesx($image); 
            $height = imagesy($image);

            $thumbWidth = $width * 0.3;
            $thumbHeight = $height * 0.3;
            $thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
            imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumbWidth , $thumbHeight, $width, $height);
            imagejpeg($thumb, '../../../images/gallery/_thumbs/' .$_FILES['file']['name'], 80);
            imagedestroy($image);
            imagedestroy($thumb);
        }
    } 
}
?>

脚本上载文件,但当它进入最后一个if的主体时,它不会创建缩略图


此代码有什么问题,如何修复

您的代码非常危险,允许恶意用户使用自己选择的jpeg图像覆盖服务器上的任何文件。您是否对代码进行过任何基本调试,比如检查所有image*()调用的返回值?你们只是假设一切都成功。我知道这是非常不安全的,但我只需要它在很短的时间内工作。问题解决了。我刚刚输入了imagecreatefromjpeg函数名。