Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Upload a Image to SQL database using FuelPHP
  • im a beginner  to fuelphp .i need to upload a image in to SQL database using fuelphp please if anyone can explain to me step by step i need with path of php files eg: fuel/app/classes/model
    please help me give me a example
      
                 Thank you..
  • HarroHarro
    Accepted Answer
    There is a usage example of the upload class in the docs: http://fuelphp.com/docs/classes/upload/usage.html

    To get it into the database you'll have to read the uploaded file into a variable after you called save(), and save it into the database. And delete the saved file from disk if you no longer need it there.

    p.s. no need to ask the same question 3 times. Once is enough.
  • I have complete this part this is my code
    public function action_index(){
    $config = array(
                'path' => DOCROOT.DS.'foldername/tomove/your/images',
                'randomize' => true,
                'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'),
            );

            Upload::process($config);

          
            if (Upload::is_valid())
            {
                
                Upload::save();

              
                $file = Upload::get_files();  
                $article->filename = $value[0]['saved_as'];
             } 
     return View::forge('sample/index');
     }

    what is my mistake 
  • I don't see where $value comes from. You mean $file?
  • <?php echo Form::open(array('name'=>'upload','enctype'=>'multipart/form-data','method'=>'post')); ?>
    <?php echo Form::file('upload'); ?>
    <?php echo Form::submit('submit', 'Upload'); ?>
    <?php echo Form::button('button', 'Uploadd'); ?>
    <?php echo Form::close(); ?>

    this is the other form
  • Apart from the two buttons, there's nothing wrong with the form.

    You show a bit of code, and ask about your mistake. But you don't say what's goes wrong. I would suggest you dump Upload::get_errors() to see what errors are detected by the process() and save() calls.

    Uploaded files with errors will not be processed, so you need to sort that out first.
  • sry sir jst i add that button

    fuel/app/modules/receipts/views/receipt_tab.php

    this is the path to code. there are more buttons and codes than this. this is a one of part

         <?php echo Form::open(array('name'=>'upload','enctype'=>'multipart/form-data','method'=>'post')); ?>
                                <?php echo Form::file('upload'); ?>              
                                <?php echo Form::submit('submit', 'Upload'); ?>
                                <?php echo Form::close(); ?>


    now i meed to give my button even on   fuel/app/classes/mainform.php  file i tried but couldn't please help me


  • Help you with what? You still haven't told me what your problem is? Does the form not work? Does the file not upload? Do you get PHP errors? Exceptions? ...

    My assumption is that Upload::save() fails, because you have configured

    'path' => DOCROOT.DS.'foldername/tomove/your/images',

    which I bet does not exist, so you get an error. Which is why I suggested you check Upload::get_errors(), it will tell you exactly what went wrong.
  • there haven't any error but don't upload the image
  • sry sry i change that path like this

    public function action_index(){
    $path='assets/img/my/';

     

     $config=array(
     'path'=>DOCROOT.DS.$path,
     'auto_rename'=>true,
     'ext_whitelist'=>array('img','jpg','jpeg','gif','png'),
     );

     Upload::process($config);
     
     if(Upload::is_valid()){
     
     Upload::save();
     $file=Upload::get_files(0);
     
     $article->filename = $value[0]['saved_as'];
     }
     
     return View::forge('sample/index');
     }

  • And? Have you checkted the result of Upload::get_errors()?
  • before that i comment this part

     return View::forge('sample/index');

    now i use it like this
    return View::forge('modules/receipts/views/receipt_tab.php');

    now i have a error like this

    Fuel\Core\FuelException [ Error ]: The requested view could not be found: modules/receipts/views/receipt_tab.php



    COREPATH/classes/view.php @ line 381





  • Error message is pretty clear?

    Does that view exist? Is the module 'receipts' loaded?
  • this form is loading but when i click on this button this error will coming i think problem is my button event i dont know give it correctly

Howdy, Stranger!

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

In this Discussion