Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6988235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:03:05+00:00 2026-05-27T19:03:05+00:00

I’ve recently managed to successfully plug the very cool Valums File Upload Plugin into

  • 0

I’ve recently managed to successfully plug the very cool Valums File Upload Plugin into an application I’m currently working on with the purpose being to upload images. I now need to modify the server side PHP scripting of this plugin to do some image manipulation (re-sizing, watermarking, thumbnail creating..etc) which I’ve been able to do before using procedural style coding, but looking at the way the upload handling is done in the valums plugin it’s all OOP.

So I’ve spent some time recently trying to get my head around OOP programing styles and I think I get the basics, but I could really use some pointers (I’m NOT asking for someone to do this for me) as to how to implement what I want to do into the existing code, things like where should my image manipulation methods go, how to get a handle on the uploaded file.

The complete code for the server side handling can be found here, but as a overview it goes a bit like this (sorry it’s still quite long):

<?php

/**
* Handle file uploads via XMLHttpRequest
*/
class qqUploadedFileXhr {

    function save($path) {
        $input = fopen("php://input", "r");
        $temp = tmpfile();
        $realSize = stream_copy_to_stream($input, $temp);
        fclose($input);

                // REMOVED VALIDATION

        $target = fopen($path, "w");
        fseek($temp, 0, SEEK_SET);
        stream_copy_to_stream($temp, $target);
        fclose($target);

        return true;
    }
    function getName() {
        return $_GET['qqfile'];
    }
    function getSize() {
            // REMOVED
    }
}

/**
* Handle file uploads via regular form post (uses the $_FILES array)
*/
class qqUploadedFileForm {

    function save($path) {
        if(!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)){
            return false;
        }
        return true;
    }
    function getName() {
        return $_FILES['qqfile']['name'];
    }
    function getSize() {
        return $_FILES['qqfile']['size'];
    }
}

class qqFileUploader {
    private $allowedExtensions = array();
    private $sizeLimit = 10485760;
    private $file;

    function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760){
        $allowedExtensions = array_map("strtolower", $allowedExtensions);

        $this->allowedExtensions = $allowedExtensions;
        $this->sizeLimit = $sizeLimit;

        $this->checkServerSettings();

        if (isset($_GET['qqfile'])) {
            $this->file = new qqUploadedFileXhr();
        } elseif (isset($_FILES['qqfile'])) {
            $this->file = new qqUploadedFileForm();
        } else {
            $this->file = false;
        }
    }

    private function checkServerSettings(){
            // REMOVED
    }

    private function toBytes($str){
            // REMOVED
    }

    /**
* Returns array('success'=>true) or array('error'=>'error message')
*/
    function handleUpload($uploadDirectory, $replaceOldFile = FALSE){

        // REMOVED VALIDATION

        $pathinfo = pathinfo($this->file->getName());
        $filename = $pathinfo['filename'];
        //$filename = md5(uniqid());
        $ext = $pathinfo['extension'];

                // REMOVED VALIDATION

        if ($this->file->save($uploadDirectory . $filename . '.' . $ext)){
            return array('success'=>true);
        } else {
            return array('error'=> 'Could not save uploaded file.' .
                'The upload was cancelled, or server error encountered');
        }

    }
}


$allowedExtensions = array("jpeg","jpg","bmp");
// max file size in bytes
$sizeLimit = 10 * 1024 * 1024;

$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload('uploads/');
// to pass data through iframe you will need to encode all html tags
echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);

?>

To clarify, I’m not after spoon feeding, but I’m struggling to get my head around where to start and seeing as I’m on a steep learning curve I don’t really want to set off down the wrong path. I could probably turn this into procedural code but I think this is a good opportunity to learn OOP properly.

Any help is greatly appreciated.

Dan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:03:06+00:00Added an answer on May 27, 2026 at 7:03 pm

    What I would try is extending the class qqFileUploader. So in psuedo code:

    class myClass extends qqFileUploader{
    
        function handleUpload(){
    
        }
    
    }
    

    Then use that handleUpload function to override what’s currently being done in that function (i.e. resizing, watermarking, etc).

    UPDATE: As I was looking closer at the question, it occurred to me that you may not mind editing the source code. I’m used to trying not to hack the core (using joomla, wordpress, etc).

    For what you’re wanting to do (intercept the file before it gets saved) you’ll want to insert your code in the handleUpload function between the if(!$replaceOldFile) statement and the if ($this->file->save($uploadDirectory . $filename . '.' . $ext)) statement.

    The variable $this->file is the file you’re wanting to edit. That’s the file you want to work your magic on. You can create your own custom functions if you want just by adding the function to the qqFileUploader class, then calling it by using $this->yourFunction().

    I hope this is can help you. If you have any more questions, I’ll try to answer them.

    SECOND UPDATE: Here’s an example of how you can manipulate the data before you save it. I just used turning the image to grayscale as an example, but you can do whatever you like. This code is to be put where I mentioned earlier, between the 2 if statements.

    $image = 'uploads/'.$this->file->getName();
    
        $im = imagecreatefrompng($image);
        if($im && imagefilter($im, IMG_FILTER_GRAYSCALE)){
            echo 'Image converted to grayscale.';
            imagepng($im, $image);
        }else{
            echo 'Conversion to grayscale failed.';
        }
        imagedestroy($im);
    

    Then you’d change this:

    if ($this->file->save($uploadDirectory . $filename . '.' . $ext))
    

    to this:

    if ($this->file->save($uploadDirectory . $im))
    

    I just tested this, so I know it will work for you. Also, I used png instead of jpeg, but that’s just because I had png’s lying around 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
I have a reasonable size flat file database of text documents mostly saved in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.