Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

phMagick Implementation Problems
  • I am trying to make some changes to some images after I upload them. Using phMagick

    the basic idea is to upload 4 images, Original, Large, Medium, Thumb
    Everything works ok until I add the phMagick then it fails, the problem I have is telling where it fails? I know it fails once I put in this
    include_once(\"core/phmagick.php\");
    $image_size = array(
    'thumbs'=>array(150,150,'resizeExactly'),
    'medium'=>array(450,450,'resize'),
    'large'=>array(900,900,'resize')
    );

    //makeUrl(round(time()/rand(1,10)).\"_\".
    $i=1;

    foreach($image_size as $var=>$val)
    {
    //$val[2] = 'resizeExactly/resize',
    //$val[0] width,
    //$val[1] height
    $phTargetPath = str_replace('//','/',$targetPath).\"/\".$var.\"/\".$filename
    if(!is_dir($phTargetPath))
    {
    mkdir($phTargetPath,0775);
    }
    //echo Pre(\"IMAGE SHOULD BE UPLOADED TO \".$filename.\"<br>\");
    ${'phMagick'.$i} = new phMagick($tempFile,$phTargetPath);
    ${'phMagick'.$i}->$val[2]($val[0],$val[1]);
    $i++;
    }


    But I cant tell what's wrong with this?, it works when called from a php page normally I have just tweaked it to use, uploadify variables instead of the usual $_FILES

    I would be grateful for anyone who can point out where I am going wrong

    The entire Uploadify script I am using is here

    if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $filename = $_FILES['Filedata']['name'];
    $targetFile = str_replace('//','/',$targetPath) . $filename;

    //Avoid files Overwrite
    while(file_exists($targetFile)){
    $user = \"g\".rand(0,100);
    $filename = $user.\"-\". $_FILES['Filedata']['name'];
    $targetFile = str_replace('//','/',$targetPath) . $filename;
    }

    move_uploaded_file($tempFile,$targetFile);

    include_once(\"core/phmagick.php\");
    $image_size = array(
    'thumbs'=>array(150,150,'resizeExactly'),
    'medium'=>array(450,450,'resize'),
    'large'=>array(900,900,'resize')
    );

    //makeUrl(round(time()/rand(1,10)).\"_\".
    $i=1;

    foreach($image_size as $var=>$val)
    {
    //$val[2] = 'resizeExactly/resize',
    //$val[0] width,
    //$val[1] height
    $phTargetPath = str_replace('//','/',$targetPath).\"/\".$var.\"/\".$filename
    if(!is_dir($phTargetPath))
    {
    mkdir($phTargetPath,0775);
    }
    //echo Pre(\"IMAGE SHOULD BE UPLOADED TO \".$filename.\"<br>\");
    ${'phMagick'.$i} = new phMagick($tempFile),$phTargetPath);
    ${'phMagick'.$i}->$val[2]($val[0],$val[1]);
    $i++;
    }
    echo \"1\";
    }

    ?>
  • After some serious tweaking I think I have solved it, after sorting out various problems with the plugins folder for phmagick and some errors within the code

    I am now left with this
    if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $filename = $_FILES['Filedata']['name'];
    $targetFile = str_replace('//','/',$targetPath) . $filename;

    //die(print_r($_REQUEST);
    // $fileTypes = str_replace('*.','',$_REQUEST['fileext']);
    // $fileTypes = str_replace(';','|',$fileTypes);
    // $typesArray = split('\|',$fileTypes);
    // $fileParts = pathinfo($_FILES['Filedata']['name']);

    //Avoid files Overwrite
    while(file_exists($targetFile)){
    $user = \"g\".rand(0,100);
    $filename = $user.\"-\". $_FILES['Filedata']['name'];
    $targetFile = str_replace('//','/',$targetPath) . $filename;
    }

    //if (in_array($fileParts['extension'],$typesArray)) {
    // Uncomment the following line if you want to make the directory if it doesn't exist
    mkdir(str_replace('//','/',$targetPath), 0775, true);

    $image_size = array(
    'thumbs'=>array(150,150),
    'medium'=>array(450,450),
    'large'=>array(900,900)
    );

    $i=1;

    move_uploaded_file($tempFile,$targetFile);
    foreach($image_size as $var=>$val)
    {
    ${'p'.$i} = new phMagick();
    $imageUrl = ${'p'.$i}->onTheFly($targetFile,$val[0],$val[1]);
    //echo '<img alt=\"\" src=\"'.$imageUrl.'\">';
    $i++;
    }

    if(exif_read_data($targetFile, 'IFD0'))
    {
    $exif = exif_read_data($targetFile, 'IFD0');
    $exif = exif_read_data($targetFile, 0, true);
    }

    //getLocalTime returns the date and time in SQL DATETIME
    //insert the information into the database
    s::$db->insert('images',
    array('path'=>$filename,
    'cid'=>$_REQUEST['cid'],
    'gid'=>$_REQUEST['gid'],
    'uid'=>$_REQUEST['uid'],
    'date_uploaded'=>getLocalTime(),
    'date_taken'=>getLocalTime($exif[FILE][FileDateTime])
    )
    );
    echo $filename;
    // } else {
    // echo 'Invalid file type.';
    // }
    }