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

  • Home
  • SEARCH
  • 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 1095027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:03:37+00:00 2026-05-17T00:03:37+00:00

I’m using Doctrine 1.2 as my ORM for a Zend Framework Project. I have

  • 0

I’m using Doctrine 1.2 as my ORM for a Zend Framework Project. I have defined the following Model for a File.

File:
    columns:
        id:
            primary: true
            type: integer(4)
            unsigned: true
        code:
            type: string(255)
            unique: true
            notblank: true
        path:
            type: string(255)
            notblank: true
        size:
            type: integer(4)
        type:
            type: enum
            values: [file,document,image,video,audio,web,application,archive]
            default: unknown
            notnull: true
        mimetype:
            type: string(20)
            notnull: true
        width:
            type: integer(2)
            unsigned: true
        height:
            type: integer(2)
            unsigned: true

Now here is the File Model php class (just skim through for now):

<?php

/**
 * File
 *
 * This class has been auto-generated by the Doctrine ORM Framework
 *
 * @package    ##PACKAGE##
 * @subpackage ##SUBPACKAGE##
 * @author     ##NAME## <##EMAIL##>
 * @version    SVN: $Id: Builder.php 6365 2009-09-15 18:22:38Z jwage $
 */
class File extends BaseFile {

 public function setUp ( ) {
  $this->hasMutator('file', 'setFile');
  parent::setUp();
 }

 public function setFile ( $file ) {
  global $Application;

  // Configuration
  $config = array();
  $config['bal'] = $Application->getOption('bal');

  // Check the file
  if ( !empty($file['error']) ) {
   $error = $file['error'];
   switch ( $file['error'] ) {
    case UPLOAD_ERR_INI_SIZE :
     $error = 'ini_size';
     break;
    case UPLOAD_ERR_FORM_SIZE :
     $error = 'form_size';
     break;
    case UPLOAD_ERR_PARTIAL :
     $error = 'partial';
     break;
    case UPLOAD_ERR_NO_FILE :
     $error = 'no_file';
     break;
    case UPLOAD_ERR_NO_TMP_DIR :
     $error = 'no_tmp_dir';
     break;
    case UPLOAD_ERR_CANT_WRITE :
     $error = 'cant_write';
     break;
    default :
     $error = 'unknown';
     break;
   }
   throw new Doctrine_Exception('error-application-file-' . $error);
   return false;
  }
  if ( empty($file['tmp_name']) || !is_uploaded_file($file['tmp_name']) ) {
   throw new Doctrine_Exception('error-application-file-invalid');
   return false;
  }

  // Prepare config
  $file_upload_path = realpath($config['bal']['files']['upload_path']) . DIRECTORY_SEPARATOR;

  // Prepare file
  $filename = $file['name'];
  $file_old_path = $file['tmp_name'];
  $file_new_path = $file_upload_path . $filename;
  $exist_attempt = 0;
  while ( file_exists($file_new_path) ) {
   // File already exists
   // Pump exist attempts
   ++$exist_attempt;
   // Add the attempt to the end of the file
   $file_new_path = $file_upload_path . get_filename($filename,false) . $exist_attempt . get_extension($filename);
  }

  // Move file
  $success = move_uploaded_file($file_old_path, $file_new_path);
  if ( !$success ) {
   throw new Doctrine_Exception('Unable to upload the file.');
   return false;
  }

  // Secure
  $file_path = realpath($file_new_path);
  $file_size = filesize($file_path);
  $file_mimetype = get_mime_type($file_path);
  $file_type = get_filetype($file_path);

  // Apply
  $this->path = $file_path;
  $this->size = $file_size;
  $this->mimetype = $file_mimetype;
  $this->type = $file_type;

  // Apply: Image
  if ( $file_type === 'image' ) {
   $image_dimensions = image_dimensions($file_path);
   if ( !empty($image_dimensions) ) {
    // It is not a image we can modify
    $this->width = 0;
    $this->height = 0;
   } else {
    $this->width = $image_dimensions['width'];
    $this->height = $image_dimensions['height'];
   }

  }

  // Done
  return true;
 }

 /**
  * Download the File
  * @return
  */
 public function download ( ) {
  global $Application;

  // File path
  $file_upload_path = realpath($config['bal']['files']['upload_path']) . DIRECTORY_SEPARATOR;
  $file_path = $file_upload_path . $this->file_path;

  // Output result and download
  become_file_download($file_path, null, null);
  die();
 }

 public function postDelete ( $Event ) {
  global $Application;
  // Prepare
  $Invoker = $Event->getInvoker();

  // Configuration
  $config = array();
  $config['bal'] = $Application->getOption('bal');

  // File path
  $file_upload_path = realpath($config['bal']['files']['upload_path']) . DIRECTORY_SEPARATOR;
  $file_path = $file_upload_path . $this->file_path;

  // Delete the file
  unlink($file_path);

  // Done
  return true;
 }
}

What I am hoping to accomplish is so that the above custom functionality within my model file can be turned into a validator, template, or something along the lines.

So hopefully I can do something like:

File:
    actAs:
        BalFile:
    columns:
        id:
            primary: true
            type: integer(4)
            unsigned: true
        code:
            type: string(255)
            unique: true
            notblank: true
        path:
            type: string(255)
            notblank: true
        size:
            type: integer(4)
        type:
            type: enum
            values: [file,document,image,video,audio,web,application,archive]
            default: unknown
            notnull: true
        mimetype:
            type: string(20)
            notnull: true
        width:
            type: integer(2)
            unsigned: true
        height:
            type: integer(2)
            unsigned: true

I’m hoping for a validator so that say if I do

$File->setFile($_FILE['uploaded_file']);

It will provide a validation error, except in all the doctrine documentation it has little on custom validators, especially in the contect of “virtual” fields.

So in summary, my question is:
How earth can I go about making a template/extension to porting this functionality? I have tried before with templates but always gave up after a day :/ If you could take the time to port the above I would greatly appreciate it.

  • 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-17T00:03:37+00:00Added an answer on May 17, 2026 at 12:03 am

    In the question I ask for a solution to problem, in the solution I came up with I eliminated the problem in the first place.

    Instead I am using SVN externals and Doctrine PEAR style models with prefixes to handle generic code. Such that there is: models/Bal/File.php, with Bal being a svn external folder. For validation, instead I decided to use static constructors such as: File::createFromUpload($_FILES[‘myFile’]) File::createFormPath($myFilePath); which would then throw an exception, that would be handled by the application business logic (controller).

    Source code visible here:
    http://github.com/balupton/balphp/blob/master/trunk/lib/models/File.php

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

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.