PHP Migration problem...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

PHP Migration problem...

Post by reverend_ink »

I moved a script for im,age upload from one server to another(with all osrts of problems).....

Talked to the hosting company and was told by them it was a script problem between php-4.1.2-7.3.6 on new server and php-4.1.2-0horde1 on the old server...

could this be? and if so here is the code and any help making the changes would be great, it uploads the file, creates the file on the server where it is supposed to be, but at 0 K file size.....

Code: Select all

<?php
$host = "localhost";
$loginname = "login";
$password = "password";
$data = "db";

@mysql_connect($host, $loginname, $password) or die(mysql_error()); 
@mysql_select_db($data) or die('Could not select database'.mysql_error()); 

if ($submit)&#123;

$sqlquery = "INSERT INTO mainpage
VALUES('$id','$title','$author','$date','$article')";

mysql_query($sqlquery);

$id = mysql_insert_id();

&#125;

if ($REQUEST_METHOD == "POST") 
&#123;

    $uploaddir = "/link/to/image/file/location/";
    

    /*== get file extension (fn at bottom of script) ==*/
    /*== checks to see if image file, if not do not allow upload ==*/
    $pext = getFileExtension($imgfile_name);
    $pext = strtolower($pext);
    if (($pext != "jpg")  && ($pext != "jpeg"))
    &#123;
        print "<h1>ERROR</h1>Image Extension Unknown.<br>";
        print "<p>Please upload only a JPEG image with the extension .jpg or .jpeg ONLY<br><br>";
        print "The file you uploaded had the following extension: $pext</p>\n";

        /*== delete uploaded file ==*/
        unlink($imgfile);
        exit();
    &#125;


    //-- RE-SIZING UPLOADED IMAGE

    /*== only resize if the image is larger than 250 x 200 ==*/
    $imgsize = GetImageSize($imgfile);

    /*== check size  0=width, 1=height ==*/
    if (($imgsize&#1111;0] > 320) || ($imgsize&#1111;1] > 240)) 
    &#123;
        /*== temp image file -- use "tempnam()" to generate the temp
             file name. This is done so if multiple people access the 
            script at once they won't ruin each other's temp file ==*/
        $tmpimg = tempnam("/tmp", "MKUP");

        /*== RESIZE PROCESS
             1. decompress jpeg image to pnm file (a raw image type) 
             2. scale pnm image
             3. compress pnm file to jpeg image
        ==*/
        
        /*== Step 1: djpeg decompresses jpeg to pnm ==*/
        system("djpeg $imgfile >$tmpimg");
        

        /*== Steps 2&3: scale image using pnmscale and then
             pipe into cjpeg to output jpeg file ==*/
        system("pnmscale -xy 320 240 $tmpimg | cjpeg -smoo 0 -qual 70 >$imgfile");

        /*== remove temp image ==*/
        unlink($tmpimg);

    &#125;

    /*== setup final file location and name ==*/
    /*== change spaces to underscores in filename  ==*/
    $final_filename = str_replace(" ", "_", $imgfile_name);
    $newfile = $uploaddir."/".$title.".jpg";
    
    /*== do extra security check to prevent malicious abuse==*/
    if (is_uploaded_file($imgfile))
    &#123;

       /*== move file to proper directory ==*/
       if (!copy($imgfile,"$newfile")) 
       &#123;
          /*== if an error occurs the file could not
               be written, read or possibly does not exist ==*/
          print "Error Uploading File.";
          exit();
       &#125;
     &#125;

    /*== delete the temporary uploaded file ==*/
    unlink($imgfile);
&#125;

?>
<body></body></html>
<?
    /*== FUNCTIONS ==*/

    function getFileExtension($str) &#123;

        $i = strrpos($str,".");
        if (!$i) &#123; return ""; &#125;

        $l = strlen($str) - $i;
        $ext = substr($str,$i+1,$l);

        return $ext;

    &#125;
?>
Thanks in advance!
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

i didnt look at the code. I doubt it is version conflict if they both use PHP 4.1.2. You mention file hadling etc, could it be permissions, safe-mode or similar diffs?
What are the errors and warnings you get?
What exactly happens or does not happen?
Post Reply