Topic: Server requirements?

What are the server requirements?

For me, Plupload works on my local server and an online testing server with Rackspace. However, the live website is to be hosted on www.heartinternet.co.uk but it's not working.

It's definitely using PHP5 - the upload appears to work and I can't find any errors. The file isn't stored and no database entries are made.

Any ideas?

Re: Server requirements?

Could be max_post size or max upload size configs in PHP. Setup a phpinfo page an look at those settings.

Re: Server requirements?

I get HTTP 200 so I doubt it?

Re: Server requirements?

Could also be mod_security. Check your server settings since this is not an issue with plupload.

Re: Server requirements?

It isn't that either. Apparently mod_security is disabled.

Thanks for the help.

Re: Server requirements?

Here's my code:

<?php include("includes/master.php"); ?>
<?php confirm_logged_in(); ini_set ( "memory_limit", "200M"); ini_set("upload_max_filesize", "8M"); ini_set("post_max_size","8M"); ?>
<?php
/**
 * upload.php
 *
 * Copyright 2009, Moxiecode Systems AB
 * Released under GPL License.
 *
 * License: [url]http://www.plupload.com/license[/url]
 * Contributing: [url]http://www.plupload.com/contributing[/url]
 */

    // HTTP headers for no cache etc
    header('Content-type: text/plain; charset=UTF-8');
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");

    // Settings
    $targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
    $finalDir  = "../uploads/"; //final directory
    $cleanupTargetDir = false; // Remove old files
    $maxFileAge = 60 * 60; // Temp file age in seconds

    // 5 minutes execution time
    @set_time_limit(5 * 60);
    // usleep(5000);

    // Get parameters
    $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
    $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
    $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';

    // Clean the fileName for security reasons
    $fileName = preg_replace('/[^\w\._]+/', '', $fileName);

    // Create target dir
    if (!file_exists($targetDir))
        @mkdir($targetDir);

    // Remove old temp files
    if (is_dir($targetDir) && ($dir = opendir($targetDir))) {
        while (($file = readdir($dir)) !== false) {
            $filePath = $targetDir . DIRECTORY_SEPARATOR . $file;

            // Remove temp files if they are older than the max age
            if (preg_match('/\\.tmp$/', $file) && (filemtime($filePath) < time() - $maxFileAge))
                @unlink($filePath);
        }

        closedir($dir);
    } else
        die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');

    // Look for the content type header
    if (isset($_SERVER["HTTP_CONTENT_TYPE"]))
        $contentType = $_SERVER["HTTP_CONTENT_TYPE"];

    if (isset($_SERVER["CONTENT_TYPE"]))
        $contentType = $_SERVER["CONTENT_TYPE"];

    if (strpos($contentType, "multipart") !== false) {
        if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
            // Open temp file
            $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
            if ($out) {
                // Read binary input stream and append it to temp file
                $in = fopen($_FILES['file']['tmp_name'], "rb");

                if ($in) {
                    while ($buff = fread($in, 4096))
                        fwrite($out, $buff);
                } else
                    die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');

                fclose($out);
                unlink($_FILES['file']['tmp_name']);
            } else
                die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
        } else
            die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
    } else {
        // Open temp file
        $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
        if ($out) {
            // Read binary input stream and append it to temp file
            $in = fopen("php://input", "rb");

            if ($in) {
                while ($buff = fread($in, 4096)){
                    fwrite($out, $buff);
                }
                
            } else
                die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
            

            fclose($out);
        } else
            die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
    }
    //Moves the file from $targetDir to $finalDir after receiving the final chunk
    if($chunk == ($chunks-1)){
        if (file_exists($finalDir . DIRECTORY_SEPARATOR . $fileName)) {
            $newfileName = rand().'_'.$fileName;            
        } else {
            $newfileName = $fileName;
        }
        $ext = pathinfo($finalDir . DIRECTORY_SEPARATOR . $fileName, PATHINFO_EXTENSION);
        if(($ext == "jpg") || ($ext == "png") || ($ext == "gif") || ($ext == "JPG") || ($ext == "PNG") || ($ext == "GIF")) {
            rename($targetDir . DIRECTORY_SEPARATOR . $fileName, $finalDir . DIRECTORY_SEPARATOR . $newfileName);
            if (!$sql =
                    mysql_query("SELECT precedence
                    FROM product_images
                    WHERE product = '".mysql_prep($_GET['product_id'])."'
                    ORDER BY precedence DESC
                    LIMIT 1")) {
                    exit('<p>Error fetching precedence.</p>');
                }

                $p = mysql_fetch_array($sql);

                $hierarchy = ($p['precedence']+1);
            $sql = "INSERT INTO product_images SET filename = '$newfileName', extension = '$ext', product='".mysql_prep($_GET['product_id'])."',precedence = '$hierarchy' ";
            if (@mysql_query($sql)) {
                $new_id = mysql_insert_id();
            }
            //BEGIN CREATE THUMBNAIL
            $size2 = getimagesize( $finalDir . DIRECTORY_SEPARATOR . $fileName );
                    // BEGIN Image for cropping
                    $maximum_width = 310;
                            
                            if ($size2[0] == $size2[1]) {
                                if ($size2[0] > $maximum_width) {
                                    $thumbnail_width2 = $maximum_width;
                                    $thumbnail_height2 = $maximum_width;
                                } else {
                                    $thumbnail_width2 = $size2[0];
                                    $thumbnail_height2 = $size2[1];
                                }
                            } elseif ($size2[0] > $size2[1] && $size2[0] < $maximum_width or $size2[1] > $size2[0] && $size2[1] < $maximum_width) {
                                $thumbnail_width2 = $size2[0];
                                $thumbnail_height2 = $size2[1];
                            } else {
                                if($size2[0] > $size2[1]) {
                                    $thumbnail_width2 = $maximum_width;
                                    $thumbnail_height2 = (int)($maximum_width * $size2[1] / $size2[0]);
                                } else {
                                    if($size2[0] > $maximum_width) {
                                        $thumbnail_width2 = $maximum_width;
                                        $thumbnail_height2 = (int)($maximum_width * $size2[1] / $size2[0]);
                                    } else {
                                        $thumbnail_width2 = $size2[0];
                                        $thumbnail_height2 = $size2[1];
                                    }
                                }
                            }
                            $function_suffix = array( 
                                'jpg' => 'JPEG',
                                'gif' => 'GIF'
                                    );
                            
                            $quality = 90;
                            // Build Thumbnail with GD 1.x.x, you can use the other described methods too
                            $function_suffix = $function_suffix[$ext];
                            $function_to_read = "ImageCreateFrom".$function_suffix;
                            $function_to_write = "Image".$function_suffix;
            
                            // Read the source file
                            $source_handle = $function_to_read ( $finalDir . DIRECTORY_SEPARATOR . $fileName  ); 
                                            
                            if($source_handle) {
                                // Let's create an blank image for the thumbnail
                                $destination_handle2 = imagecreatetruecolor( $thumbnail_width2, $thumbnail_height2 );
                            
                                // Now we resize it
                                imagecopyresampled( $destination_handle2, $source_handle, 0, 0, 0, 0, $thumbnail_width2, $thumbnail_height2, $size2[0], $size2[1] );
                            }
                            
                            // Let's save the thumbnail
                            $function_to_write( $destination_handle2, $finalDir . DIRECTORY_SEPARATOR . "small_".$fileName , $quality);
                            imagedestroy($destination_handle2 );
                            
                            //mysql_query( "UPDATE other SET ni_width='".addslashes($thumbnail_width2)."', ni_height='".addslashes($thumbnail_height2)."' WHERE id='".addslashes($new_id)."' LIMIT 1" );
                            
                                        
            //END CREATE THUMBNAIL
            //BEGIN CREATE THUMBNAIL
            $size3 = getimagesize( $finalDir . DIRECTORY_SEPARATOR . $fileName );
                    // BEGIN Image for cropping
                    $maximum_width = 150;
                            
                            if ($size3[0] == $size3[1]) {
                                if ($size3[0] > $maximum_width) {
                                    $thumbnail_width3 = $maximum_width;
                                    $thumbnail_height3 = $maximum_width;
                                } else {
                                    $thumbnail_width3 = $size3[0];
                                    $thumbnail_height3 = $size3[1];
                                }
                            } elseif ($size3[0] > $size3[1] && $size3[0] < $maximum_width or $size3[1] > $size3[0] && $size3[1] < $maximum_width) {
                                $thumbnail_width3 = $size3[0];
                                $thumbnail_height3 = $size3[1];
                            } else {
                                if($size3[0] > $size3[1]) {
                                    $thumbnail_width3 = $maximum_width;
                                    $thumbnail_height3 = (int)($maximum_width * $size3[1] / $size3[0]);
                                } else {
                                    if($size3[0] > $maximum_width) {
                                        $thumbnail_width3 = $maximum_width;
                                        $thumbnail_height3 = (int)($maximum_width * $size3[1] / $size3[0]);
                                    } else {
                                        $thumbnail_width3 = $size3[0];
                                        $thumbnail_height3 = $size3[1];
                                    }
                                }
                            }
                            $function_suffix = array( 
                                'jpg' => 'JPEG',
                                'gif' => 'GIF'
                                    );
                            
                            $quality = 90;
                            // Build Thumbnail with GD 1.x.x, you can use the other described methods too
                            $function_suffix = $function_suffix[$ext];
                            $function_to_read = "ImageCreateFrom".$function_suffix;
                            $function_to_write = "Image".$function_suffix;
            
                            // Read the source file
                            $source_handle = $function_to_read ( $finalDir . DIRECTORY_SEPARATOR . $fileName  ); 
                                            
                            if($source_handle) {
                                // Let's create an blank image for the thumbnail
                                $destination_handle3 = imagecreatetruecolor( $thumbnail_width3, $thumbnail_height3 );
                            
                                // Now we resize it
                                imagecopyresampled( $destination_handle3, $source_handle, 0, 0, 0, 0, $thumbnail_width3, $thumbnail_height3, $size3[0], $size3[1] );
                            }
                            
                            // Let's save the thumbnail
                            $function_to_write( $destination_handle3, $finalDir . DIRECTORY_SEPARATOR . "thumb_".$fileName , $quality);
                            imagedestroy($destination_handle2 );
                            
                            //mysql_query( "UPDATE other SET ni_width='".addslashes($thumbnail_width3)."', ni_height='".addslashes($thumbnail_height3)."' WHERE id='".addslashes($new_id)."' LIMIT 1" );
                            
                                        
            //END CREATE THUMBNAIL
        } else {
            rename($targetDir . DIRECTORY_SEPARATOR . $fileName, $finalDir . DIRECTORY_SEPARATOR . $newfileName);
                if (!$sql =
                    mysql_query("SELECT precedence
                    FROM product_files
                    WHERE product = '".mysql_prep($_GET['product_id'])."'
                    ORDER BY precedence DESC
                    LIMIT 1")) {
                    exit('<p>Error fetching precedence.</p>');
                }

                $p = mysql_fetch_array($sql);

                $hierarchy = ($p['precedence']+1);
            $sql = "INSERT INTO product_files SET filename = '$newfileName', extension = '$ext', product='".mysql_prep($_GET['product_id'])."',precedence = '$hierarchy' ";
            if (@mysql_query($sql)) {
                $new_id = mysql_insert_id();
            }
        }
    }

    // Return JSON-RPC response
    die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');
?>

Perhaps the temporary file directory isn't being found?

Re: Server requirements?

My host has just said:

"The only thing we restrict on our servers are 'loopback' connections, that is the a script attempting to make an HTTP connection to the same server."

Could this be the problem?