首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP&jQueryPHP-共享FileAPI服务器配置

PHP&jQueryPHP-共享FileAPI服务器配置
EN

Stack Overflow用户
提问于 2013-12-29 00:47:13
回答 1查看 626关注 0票数 1

我让我的用户裁剪和上传他们的图片与jQuery FileAPI。我从另一个页面用jQuery调用这个PHP文件。

在我的本地服务器上一切正常工作,但是当将它上传到我的生产(共享- cPanel)服务器时,它不会创建这个文件。

你知道我是否需要在我的cPanel上改变什么或者打电话给我的托管公司?

我尝试使用头访问来进行推特,但是没有任何效果。

以下是PHP文件:

代码语言:javascript
复制
<?php include 'init.php'; ?>
<?php
if(logged_in() === false) {
 header('Location: login.php');
 exit();
} ?>
<?php
/**
 * FileAPI upload controller (example)
 */


include    'FileAPI.class.php';



if( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' ){
    exit;
}


if( strtoupper($_SERVER['REQUEST_METHOD']) == 'POST' ){
    $files  = FileAPI::getFiles(); // Retrieve File List
    $images = array();


    // Fetch all image-info from files list
    fetchImages($files, $images);


    // JSONP callback name
    $jsonp  = isset($_REQUEST['callback']) ? trim($_REQUEST['callback']) : null;


    // JSON-data for server response
    $json   = array(
          'images'  => $images
        , 'data'    => array('_REQUEST' => $_REQUEST, '_FILES' => $files)
    );


    // Server response: "HTTP/1.1 200 OK"
    FileAPI::makeResponse(array(
          'status' => FileAPI::OK
        , 'statusText' => 'OK'
        , 'body' => $json
    ), $jsonp);
    exit;
}

function fetchImages($files, &$images, $name = 'file'){
    if( isset($files['tmp_name']) ){
        $filename = $files['tmp_name'];
        list($mime) = explode(';', @mime_content_type($filename));

        if( strpos($mime, 'image') !== false ){
            $size = getimagesize($filename);
            $base64 = base64_encode(file_get_contents($filename));

            $images[$name] = array(
                  'width'   => $size[0]
                , 'height'  => $size[1]
                , 'mime'    => $mime
                , 'size'    => filesize($filename)
                , 'dataURL' => 'data:'. $mime .';base64,'. $base64
            );

            $iWidth = $iHeight = 330; // desired image result dimensions
            $iJpgQuality = 100;

            // new unique filename
            $sTempFileName = 'userpics/' . md5(time().rand());

             // move uploaded file into cache folder
             move_uploaded_file($filename, $sTempFileName);

              // change file permission to 644
             @chmod($sTempFileName, 0644);

                    if (file_exists($sTempFileName) && filesize($sTempFileName) > 0) {
                        $aSize = getimagesize($sTempFileName); // try to obtain image info
                        if (!$aSize) {
                            @unlink($sTempFileName);
                            return;
                        }

                        // check for image type
                        switch($aSize[2]) {
                            case IMAGETYPE_JPEG:
                                $sExt = '.jpg';

                                // create a new image from file 
                                $vImg = @imagecreatefromjpeg($sTempFileName);
                                break;
                            case IMAGETYPE_GIF:
                                $sExt = '.gif';

                                // create a new image from file 
                                $vImg = @imagecreatefromgif($sTempFileName);
                                break;
                            case IMAGETYPE_PNG:
                                $sExt = '.png';

                                // create a new image from file 
                                $vImg = @imagecreatefrompng($sTempFileName);
                                break;
                            default:
                                @unlink($sTempFileName);
                                return;
                        }
                        $data = getimagesize($sTempFileName);
                        $width = $data[0];
                        $height = $data[1];
                        // create a new true color image
                        $vDstImg = @imagecreatetruecolor( $iWidth, $iHeight );

                        // copy and resize part of an image with resampling
                        imagecopyresampled($vDstImg, $vImg, 0, 0, 0, 0, $iWidth, $iHeight, $width, $height);
                        // define a result image filename
                        $sResultFileName = $sTempFileName . $sExt;

                        // output image to file
                        imagejpeg($vDstImg, $sResultFileName, $iJpgQuality);           


                        @unlink($sTempFileName);

                        $user_id = $_SESSION['user_id'];
                        add_guest_picture($user_id, $sResultFileName);

                       // return $sResultFileName;
                    }  


        }
    }
    else {
        foreach( $files as $name => $file ){
            fetchImages($file, $images, $name);
        }
    }
}
?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-29 21:23:17

好的问题解决了!

显然,mime_content_type没有得到我的主人的支持。在删除Musa建议的错误抑制之后,我可以捕获错误。

我要求我的主机启用我的mime php处理,现在一切都正常了。

干杯。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20821007

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档