Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.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 图像上载,无法识别文件扩展名_Php_Forms_Apache_Post_Upload - Fatal编程技术网

Php 图像上载,无法识别文件扩展名

Php 图像上载,无法识别文件扩展名,php,forms,apache,post,upload,Php,Forms,Apache,Post,Upload,我使用本教程构建了一个图像上传程序 这使用了图书馆 然而,每当我通过表单向其传递文件时,最后一个IF语句总是失败(请上传图像) 代码如下: <?php require_once(dirname(__FILE__).'/../config.php'); require_once(dirname(__FILE__).'/ImageManipulator.php'); if ($_FILES['fileToUpload']['error'] > 0) { echo "Erro

我使用本教程构建了一个图像上传程序

这使用了图书馆

然而,每当我通过表单向其传递文件时,最后一个IF语句总是失败(请上传图像)

代码如下:

<?php
require_once(dirname(__FILE__).'/../config.php');
require_once(dirname(__FILE__).'/ImageManipulator.php');

if ($_FILES['fileToUpload']['error'] > 0) {
    echo "Error: " . $_FILES['fileToUpload']['error'] . "<br />";
} else {
    // array of valid extensions
    $validExtensions = array('.jpg', '.jpeg', '.gif', '.png', '.JPG', '.JPEG', '.PNG', '.GIF', '.bmp');
    // get extension of the uploaded file
    $fileExtension = strrchr($_FILES['fileToUpload']['name'], ".");
    // check if file Extension is on the list of allowed ones
    if (in_array($fileExtension, $validExtensions)) {
        $newNamePrefix = time() . '_';
        $manipulator = new ImageManipulator($_FILES['fileToUpload']['tmp_name']);
        $width  = $manipulator->getWidth();
        $height = $manipulator->getHeight();
        $centreX = round($width / 2);
        $centreY = round($height / 2);
        // our dimensions will be 80by80
        $x1 = $centreX - 40; // 80
        $y1 = $centreY - 40; // 80

        $x2 = $centreX + 40; // 80
        $y2 = $centreY + 40; // 80

        // center cropping to 80by80
        $newImage = $manipulator->crop($x1, $y1, $x2, $y2);
        // saving file to uploads folder
        $manipulator->save('/images/avatars/uploaded/' . $newNamePrefix . $_FILES['fileToUpload']['name']);
        echo 'Done ...';
    } else {
        echo 'You must upload an image...';
    }
}
?> 
编辑:深入挖掘,这似乎是一个权限问题

SITE:[Sat Jul 19 21:31:58 2014] [error] [client 82.46.57.58] PHP   2. ImageManipulator->save() /SITE/lib/uploadimage.php:30, referer: SITE/index.php
SITE:[Sat Jul 19 21:31:58 2014] [error] [client 82.46.57.58] PHP   3. mkdir() /SITE/lib/ImageManipulator.php:222, referer: SITE/index.php
SITE:[Sat Jul 19 21:31:58 2014] [error] [client 82.46.57.58] PHP Fatal error:  Uncaught exception 'RuntimeException' with message 'Error creating directory /images/avatars/uploaded' in /SITE/lib/ImageManipulator.php:223\nStack trace:\n#0 /SITE/lib/uploadimage.php(30): ImageManipulator->save('/images/avatars...')\n#1 {main}\n  thrown in /SITE/lib/ImageManipulator.php on line 223, referer: SITE/index.php

它是基于权限的,并且在映像目录中有一个小错误

它应该是../images,并且文件夹需要由www数据拥有

log:[Sat Jul 19 20:48:51 2014] [error] [client 82.46.57.58] PHP Notice:  Undefined index: fileToUpload in /var/SITE/lib/uploadimage.php on line 5, referer: SITE/index.php
SITE:[Sat Jul 19 21:31:58 2014] [error] [client 82.46.57.58] PHP   2. ImageManipulator->save() /SITE/lib/uploadimage.php:30, referer: SITE/index.php
SITE:[Sat Jul 19 21:31:58 2014] [error] [client 82.46.57.58] PHP   3. mkdir() /SITE/lib/ImageManipulator.php:222, referer: SITE/index.php
SITE:[Sat Jul 19 21:31:58 2014] [error] [client 82.46.57.58] PHP Fatal error:  Uncaught exception 'RuntimeException' with message 'Error creating directory /images/avatars/uploaded' in /SITE/lib/ImageManipulator.php:223\nStack trace:\n#0 /SITE/lib/uploadimage.php(30): ImageManipulator->save('/images/avatars...')\n#1 {main}\n  thrown in /SITE/lib/ImageManipulator.php on line 223, referer: SITE/index.php