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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:11:13+00:00 2026-05-28T02:11:13+00:00

I have a problem to upload an image using Symfony. I have a form

  • 0

I have a problem to upload an image using Symfony.

I have a form where I get the links of banners, those banners are hosted on different websites.

But, I need to save them on my server, how to do it in an action class in Symfony?

Thank you

  • 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-28T02:11:13+00:00Added an answer on May 28, 2026 at 2:11 am

    Don’t use an action, use a form!

    You create a simple text input, but you use a custom validator extending the sfValidatorFile (used for classic file upload). This validator is returning a sfValidatedFile, safe and really easy to save with the save() method.

    Here is an example code of my own:

    <?php
    
    /**
     * myValidatorWebFile simule a file upload from a web url (ftp, http)
     * You must use the validation options of sfValidatorFile
     * 
     * @package    symfony
     * @subpackage validator
     * @author     dalexandre
     */
    class myValidatorWebFile extends sfValidatorFile
    {
      /**
       * @see sfValidatorBase
       */
      protected function configure($options = array(), $messages = array())
      {
        parent::configure($options, $messages);
      }
    
      /**
       * Fetch the file and put it under /tmp
       * Then simulate a web upload and pass through sfValidatorFile
       * 
       * @param url $value
       * @return sfValidatedFile
       */
      protected function doClean($value)
      {
        $file_content = file_get_contents($value);
        if ($file_content) 
        {
          $tmpfname = tempnam("/tmp", "SL");
          $handle = fopen($tmpfname, "w");
          fwrite($handle, $file_content);
          fclose($handle);
    
          $fake_upload_file = array();
          $fake_upload_file['tmp_name'] = $tmpfname;
          $fake_upload_file['name']     = basename($value);
    
          return parent::doClean($fake_upload_file);
        }
        else
        {
          throw new sfValidatorError($this, 'invalid');
        }
      }
    
      /**
       * Fix a strange bug where the string was declared has empty...
       */
      protected function isEmpty($value)
      {
        return empty ($value);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image upload form <% using (Html.BeginForm(PictureValidateAndSave, UserGallery, new {}, FormMethod.Post, new
Using Symfony 1.4.5 with Doctrine I have a model which includes an uploaded image
I have a ajax image upload script which i found here http://www.fengcool.com/2009/06/ajax-form-upload-local-image-file-without-refresh/ The problem
I have a post type which is used to upload banners in wordpress. Using
I have a site where I can upload an image, and i am using
I have been using to upload an image file from HTML5/JS and using PHP
I have a problem. I upload some images from HDD to the website using
I have problem with uploading image to SQL database. i have Methods Upload in
I'm developing small FTP upload app. for mac (10.6 if it matters) Have problem
I have a bash script to upload some files to my webserver. The problem

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.