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 8350337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:17:12+00:00 2026-06-09T08:17:12+00:00

Im develloping with symfony1.0,I’m using a file validation(validate/upload.yml) like that : methods: post: [logo_file]

  • 0

Im develloping with symfony1.0,I’m using a file validation(validate/upload.yml) like that :

    methods:
              post:               [logo_file]
              get:                [logo_file]

    names:
              logo_file:
              required:         Yes
              required_msg:     Please select a file to upload 23008
              validators:       myFileValidator
               file:             true

    myFileValidator:
              class:              sfFileValidator
              param:
                    mime_types:       
                            - 'image/jpeg'
                            - 'image/png'
                            - 'image/gif'
                            - 'image/x-png'
                            - 'image/pjpeg'    
    mime_types_error: Only PNG, GIF and JPEG images files are allowed 23009
    max_size:         512000
    max_size_error:   Max size is 512Kb 23010

And all is fine until now but I wanna also make a validation for name of image,I hope to sanitze the name from Invalid character before stroring at database?

EDIT

Of course not so now Im using a function before sving in DB :

    public static function generateUniqueName($fileName, $fileExtension)
{
    // Create a name 
    $fileUniqueSuffix=PublicIdGeneratorPeer::getPublicIdForTable(self::UNIQUE_FILE_ID);
    $finalFileName = $fileName.'-'.$fileUniqueSuffix.$fileExtension;

   //here I want to replace or remove invalid character from  $filename 

    return $finalFileName;
}

EDIT-2 :

So now I have a lot of name of image stored in database with invlaid charater,so I hope to create a script or a way to travel all data in feald “image_name” and change all invalid character in DB directly,my first idea it’s to use a “task”?!Any idea?

EDIT-3 :

So now I make my batch like that :

<?php
   define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/..'));
   define('SF_APP',         'backend');
   define('SF_ENVIRONMENT', 'prod');
    define('SF_DEBUG',       false);

   // symfony directories
      require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');

     sfContext::getInstance();

 /********************************** Begin **********************************/


         $criteria = new Criteria();
           $listCompanyLogo = CompanyLogoPeer::doSelect($criteria);


         foreach($listCompanyLogo as $CompanyLogo)
      {
 if(!is_null($CompanyLogo))
       {


       $filename= $CompanyLogo->getFileName();
       $filepath=$CompanyLogo->getFilePath();
       $fileurl=$CompanyLogo->getFileUrl();



       $finalFileName=StringTool::stripText($filename);
       $finalFilePath=StringTool::cleanUrl($filename,$filepath);
       $finalFileUrl=StringTool::cleanUrl($filename,$fileurl);



       $CompanyLogo->setFileName($finalFileName);
       $CompanyLogo->setFilePath($finalFilePath);
       $CompanyLogo->setFileUrl($finalFileUrl);


       $CompanyLogo->save();

       echo ' the name of logo : '.$filename.' is modified by  ==============>'.$finalFileName.'<br>' ;
       exit();
       }

       }

         /********************************** End **********************************/
       ?>

So I can change the invalid character from the name of file in database,my new problem is how to change the name of file in his direcotry,I mean change the name of file of the file itself,I dont know how?

Edit-4

So here it’s my final code :

batch/updatelogoName.php

   <?php
   define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/..'));
   define('SF_APP',         'backend');
   define('SF_ENVIRONMENT', 'prod');
   define('SF_DEBUG',       false);

    // symfony directories
           require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');

   sfContext::getInstance();

   /********************************** Begin **********************************/


   $criteria = new Criteria();
   $listCompanyLogo = CompanyLogoPeer::doSelect($criteria);


foreach($listCompanyLogo as $CompanyLogo)
 {
 if(!is_null($CompanyLogo))
       {


       $filename= $CompanyLogo->getFileName();
       $filepath=$CompanyLogo->getFilePath();
       $fileurl=$CompanyLogo->getFileUrl();
       $thumbnailName= $CompanyLogo->getThumbnailName();
       $ThumbnailPath= $CompanyLogo->getThumbnailPath();
       $ThumbnailUrl= $CompanyLogo->getThumbnailUrl();


       $finalFileName=StringTool::cleanName($filename);
       $finalFilePath=StringTool::cleanUrl($filename,$filepath);
       $finalFileUrl=StringTool::cleanUrl($filename,$fileurl);
       $finalThumbnailName=StringTool::cleanName($thumbnailName);
       $finalThumbnailPath=StringTool::cleanUrl($filename,$ThumbnailPath);
       $finalThumbnailUrl=StringTool::cleanUrl($filename,$ThumbnailUrl);


       $CompanyLogo->setFileName($finalFileName);
       $CompanyLogo->setFilePath($finalFilePath);
       $CompanyLogo->setFileUrl($finalFileUrl);
       $CompanyLogo->setThumbnailName($finalThumbnailName);
       $CompanyLogo->setThumbnailPath($finalThumbnailPath);
       $CompanyLogo->setThumbnailUrl($finalThumbnailUrl);

       $CompanyLogo->save();


       if(rename('../web/'.$ThumbnailUrl, '../web/'.$finalThumbnailUrl) !== 'false')
       {
             rename('../web/'.$ThumbnailUrl, '../web/'.$finalThumbnailUrl);
       }

       echo 'The logo : '.$filename.' is modified by ==============>'.$finalFileName.'<br>' ;

       }

 }

    /********************************** End **********************************/
  ?>

Class StringTool.php :

            public static function stripText($text)
    {
        $accFrom = array('ë','é','è','ê','Ê','Ë','É','È','à','â','á','ä','ã','å','Â','Å','À','Á','Ã','Ä','ç','Ç','Î','Ï','Ì','Í','ì','í','î','ï','Ó','Ô','Õ','Ö','ò','ó','ô','õ','ö','Ù','Ú','Û','Ü','ù','ú','û','ü');
        $accTo =   array('e','e','e','e','e','e','e','e','a','a','a','a','a','a','a','a','a','a','a','a','c','c','i','i','i','i','i','i','i','i','o','o','o','o','o','o','o','o','o','u','u','u','u','u','u','u','u');

        $text = str_replace($accFrom,$accTo,$text);

        $text = strtolower($text);

        // strip all non word chars
        $text = preg_replace('/\W/', ' ', $text);

        // replace all white space sections with a dash
        $text = preg_replace('/\ +/', '-', $text);

        // trim dashes
        $text = preg_replace('/\-$/', '', $text);
        $text = preg_replace('/^\-/', '', $text);

        return $text;
    }

     /*
     * Remove extnesion File
     * 
     */

     public static function RemoveExtension($fileName)
         {
            $extension = strrchr($fileName, '.');

            if($extension !== false)
              {
                $fileName = substr($fileName, 0, -strlen($extension));
              }
            return $fileName;
         }

     /*
     * Remove all non alpha-numeric characters from URLs and Files
     * 
     */


      public static function  cleanName ($fileName)
        {

         $extension = pathinfo($fileName, PATHINFO_EXTENSION);
         $extremove = self::RemoveExtension($fileName);
         $result = self::stripText($extremove);

         $finaleFileName= $result.'.'.$extension;

         return $finaleFileName;

        }

      public static function cleanUrl($fileName,$filePath)
        {

         $finaleFileName = self::cleanName($fileName);
         $finaleFilePath=str_replace($fileName, $finaleFileName, $filePath);

         return $finaleFilePath;
        }

If you see any error or optimization tell me…

  • 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-06-09T08:17:13+00:00Added an answer on June 9, 2026 at 8:17 am

    You can cleanup your file name in your generateUniqueName function using a striptext method. For example, the one used in Askeet:

    <?php
    
    class myTools
    {
      public static function stripText($text)
      {
        $text = strtolower($text);
    
        // strip all non word chars
        $text = preg_replace('/\W/', ' ', $text);
    
        // replace all white space sections with a dash
        $text = preg_replace('/\ +/', '-', $text);
    
        // trim dashes
        $text = preg_replace('/\-$/', '', $text);
        $text = preg_replace('/^\-/', '', $text);
    
        return $text;
      }
    }
    

    Then:

    public static function generateUniqueName($fileName, $fileExtension)
    {
        // Create a name 
        $fileUniqueSuffix = PublicIdGeneratorPeer::getPublicIdForTable(self::UNIQUE_FILE_ID);
        $finalFileName    = myTools::stripText($fileName).'-'.$fileUniqueSuffix.$fileExtension;
    
        return $finalFileName;
    }
    

    edit:

    And for your second request, you should create a task. In fact, it’s a task but it’s called batch in sf1.0. See the short doc here. Basically:

    • you fetch all your image table
    • you sanitize all name
    • you rename all image on disk with the new name

    edit 2:

    If you have problem with utf8, you should check with urlize from Doctrine_Inflector.

    Then use:

    $finalFileName    = Doctrine_Inflector::urlize($fileName).'-'.$fileUniqueSuffix.$fileExtension;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am develping a project using symfony1.4.16 and Doctrine and for authentication i am
I would like to start using TDD in my PHP projects using Symfony 1.4
I am developing an application using symfony2. I would like to know how I
I develloping a simple website using spring-mvc. The question is what is the best
I'm develloping an android application that has a local database which synchronizes whith an
I have a try-catch block that iterates over a set of records like this:
I'm currently developing an application using Symfony 2 and would like my routes to
I'm developing a Symfony 1.4 plugin and I noticed that plugin routes get matched
Currently developing an application using the newest version of symfony, obtained through PEAR. This
I am developing an application using Symfony 1.4. Is it posible to disable a

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.