Yii Framework Forum: Xupload And Model - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Xupload And Model i canot save image with model

#1 User is offline   dony 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 28-May 12
  • Location:Ukraine. Kiev

Posted 19 January 2013 - 10:44 AM

Hello. i want integrate XUpload to my yii application. But i have 2 problems:
1. after upload image they correctly saved to tmp folder
//protected/controllers/SiteController.php (line 95)

//Move our file to our temporary dir
$model->file->saveAs( $path.$filename );
chmod( $path.$filename, 0777 );

But in model when tmp image must move to another folder and rename to real image name (exmaple: photo.jpg)
//protected/models/Images.php (line 108)

if (rename($image["path"], $path . $image["filename"])) {
    chmod($path . $image["filename"], 0777);
    $img = new Image();
    $img->size = $image["size"];
    $img->mime = $image["mime"];
    $img->name = $image["name"];
    $img->source = "/images/uploads/{$this->id}/" . $image["filename"];
    $img->somemodel_id = $this->id;
    if (!$img->save()) {
        //Its always good to log something
        Yii::log("Could not save Image:\n" . CVarDumper::dumpAsString(
                        $img->getErrors()), CLogger::LEVEL_ERROR);
        //this exception will rollback the transaction
        throw new Exception('Could not save Image');

its not happen. image moved. but not rename. This is part of code not execute, but why?

2. At this app i have 1 filed - title and XUpload form. I want to save all uploaded image to database, but i dint now how its make and i have error in step
I follow to this manual http://www.yiiframew...load-workflow/. Help me please. I am the second day trying to make it.

P.S. I upload my app - http://yadi.sk/d/ioG6Tvyq1yVRA for greater clarity. Dump of db in data folder. And sorry for my english

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 3,710
  • Joined: 10-October 10
  • Location:Denmark

Posted 19 January 2013 - 11:23 AM

/* moved from General Discussion */
"Less noise - more signal"

#3 User is offline   Asgaroth 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 371
  • Joined: 17-July 09
  • Location:Bogota, Colombia

Posted 20 January 2013 - 11:35 AM

clearly your code:

rename($image["path"], $path . $image["filename"])

Is returning false, that means It cant rename it for some reason, try to check that `$image["path"]` exists, and that `$path . $image["filename"]` is a valid path, and that is writable
- Extension: Dynamic DataProvider Behavior
- Extension: XUpload - jQuery File Upload Extension
- Extension: PhpQuickProfiler - A Web Log Router that will help you profile your application
- Extension: XDateView - A Date grouped Grid View
- Extension: Foundation - An easy to use, powerful, and flexible framework for building prototypes and production code on any kind of device.

- Wiki: How to generate Yii like Documentation
- Wiki: How to re enable logging during unit testing

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users