Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

New file upload doesnt work but choose existing files works


Go to End


6 Posts   2251 Views

Avatar
BuddhaSource

Community Member, 57 Posts

16 January 2012 at 6:00am

Hi,

I was hoping if someone else had the same problem and could help me out.

To start with I have updated dataobject_manager, image_gallery and uploadify from github.

When I try to upload a new image it doesn't get attached after upload. However if I choose from existing I am able to import and works as expected.

I have cross checked db & folder, the file is successfully uploaded but for some reason doesn't attach itself.

My GalleryImage.php

class GalleryImage extends DataObject
{
   static $db = array (
      'ImageTitle' => 'Text',     
   );
   
	static $default_parent = null; // NOTE: has to be a URL segment NOT a class name
    static $can_be_root = FALSE;
	
   static $has_one = array (
      'MyGalleryImage' => 'Image', //relation needed for this DataObject
      //'BelongToEventPage' => 'EventPage' //relation needed to point back to your pagetype, my pagetype is EventPage.
      'BelongToBlogEntryPage' => 'BlogEntry'
   );
   
   public function getCMSFields_forPopup()
   {
      return new FieldSet(
         new TextField('ImageTitle'),
         new FileIFrameField('MyGalleryImage')
      );
   }
} 


.....

	static $has_many = array (
          'GalleryImages' => 'GalleryImage'
    );

.....		

function getCMSFields() {
	$manager = new ImageDataObjectManager(
         $this, // Controller
        'GalleryImages', // Source name
        'GalleryImage', // Source class
        'MyGalleryImage', // File name on DataObject
         array(
            'GalleryImageTitle' => 'GalleryImageTitle'
         ), // Headings
         'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
         // Filter clause
         // Sort clause
         // Join clause
      );
      $fields->addFieldToTab('Root.Content.GalleryImage', $manager); 
     return $fields;
    }

.....

Avatar
Bereusei

Community Member, 96 Posts

16 January 2012 at 9:22am

I´ve got the same problem a time ago. Check that you doesn´t close the <?php
Check if you doesn´t have at the end of your php-files " ?> ".

Avatar
Sticks

Community Member, 31 Posts

16 January 2012 at 10:56am

I've had this problem before too, and similar to Bereusei it had to do with the php tags. My exact problem was that on one of my page class files I had the opening '<?php' on the second line of the document. Moving it up to the first line solved the problem.

Avatar
BuddhaSource

Community Member, 57 Posts

16 January 2012 at 5:37pm

Edited: 16/01/2012 5:43pm

Okay I removed " ?> " but no help.

Should I remove <?php and ?> from all .php files ?

When I upload the file, it uploads correctly but does not show in attached files.

Edit.

I checked my firebug & got this error in console.

NetworkError: 500 Internal Server Error - http://test.mydomain.com/admin/EditForm/field/GalleryImages/UploadifyForm/field/UploadedFiles/refresh?SecurityID=6e334a93b822455926009cbec9934a29167e7eb0&ctf[GalleryImages][start]=0&ctf[GalleryImages][per_page]=10&ctf[GalleryImages][showall]=0&ctf[GalleryImages][sort]=&ctf[GalleryImages][sort_dir]=&ctf[GalleryImages][search]=&ctf[GalleryImages][filter]=&ctf[GalleryImages][view]=grid&ctf[GalleryImages][imagesize]=100&FileIDs=%0D%0A%0D%0A43925

Avatar
Sticks

Community Member, 31 Posts

16 January 2012 at 5:43pm

Edited: 16/01/2012 5:44pm

You need to remove all instances of ?> from all php files, but you still need to have the <?php in each file. Like I said, make sure the <?php is on the very first line of each document.

There may be other white space issues that I don't know about too. Try removing empty lines and spaces from the end of files. I think I've also needed to add an empty second line to an empty _config.php file at one stage too. All of that is tedious and awkward, but that's how I've solved this problem in the past.

(I'd love to know if there's a better way to debug this...).

Avatar
BuddhaSource

Community Member, 57 Posts

16 January 2012 at 5:46pm

Edited: 16/01/2012 5:47pm

I think its something else. I just checked my post response from Firebug and got this


ERROR [User Error]: Couldn't run query: 
SELECT "File"."ClassName", "File"."Created", "File"."LastEdited", "File"."Name", "File"."Title", "File"."Filename", "File"."Content", "File"."Sort", "File"."ShowInSearch", "File"."SortOrder", "File"."ParentID", "File"."OwnerID", "File"."ID", CASE WHEN "File"."ClassName" IS NOT NULL THEN "File"."ClassName" ELSE 'File' END AS "RecordClassName"
FROM "File"
WHERE ("File"."ID" IN (\r\n\r\n43925))
ORDER BY "SortOrder" ASC 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\r\n\r\n43925)) ORDER BY "SortOrder" ASC' at line 1
IN GET /admin/EditForm/field/GalleryImages/UploadifyForm/field/UploadedFiles/refresh?SecurityID=6e334a93b822455926009cbec9934a29167e7eb0&ctf[GalleryImages][start]=0&ctf[GalleryImages][per_page]=10&ctf[GalleryImages][showall]=0&ctf[GalleryImages][sort]=&ctf[GalleryImages][sort_dir]=&ctf[GalleryImages][search]=&ctf[GalleryImages][filter]=&ctf[GalleryImages][view]=grid&ctf[GalleryImages][imagesize]=100&FileIDs=%0D%0A%0D%0A43925
Line 525 in /home/test/public_html/sapphire/core/model/MySQLDatabase.php

Source
======
  516: 	}
  517: 	
  518: 	function databaseError($msg, $errorLevel = E_USER_ERROR) {
  519: 		// try to extract and format query
  520: 		if(preg_match('/Couldn\'t run query: ([^\|]*)\|\s*(.*)/', $msg, $matches)) {
  521: 			$formatter = new SQLFormatter();
  522: 			$msg = "Couldn't run query: \n" . $formatter->formatPlain($matches[1]) . "\n\n" . $matches[2];
  523: 		}
  524: 		
* 525: 		user_error($msg, $errorLevel);
  526: 	}
  527: 	
  528: 	/**
  529: 	 * Return a boolean type-formatted string
  530: 	 * 
  531: 	 * @param array $values Contains a tokenised list of info about this data type

Trace
=====
<ul>user_error(Couldn't run query: 
SELECT "File"."ClassName", "File"."Created", "File"."LastEdited", "File"."Name", "File"."Title", "File"."Filename", "File"."Content", "File"."Sort", "File"."ShowInSearch", "File"."SortOrder", "File"."ParentID", "File"."OwnerID", "File"."ID", CASE WHEN "File"."ClassName" IS NOT NULL THEN "File"."ClassName" ELSE 'File' END AS "RecordClassName"
FROM "File"
WHERE ("File"."ID" IN (\r\n\r\n43925))
ORDER BY "SortOrder" ASC 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\r\n\r\n43925)) ORDER BY "SortOrder" ASC' at line 1,256)
line 525 of MySQLDatabase.php

MySQLDatabase->databaseError(Couldn't run query: SELECT "File"."ClassName", "File"."Created", "File"."LastEdited", "File"."Name", "File"."Title", "File"."Filename", "File"."Content", "File"."Sort", "File"."ShowInSearch", "File"."SortOrder", "File"."ParentID", "File"."OwnerID", "File"."ID", CASE WHEN "File"."ClassName" IS NOT NULL THEN "File"."ClassName" ELSE 'File' END AS "RecordClassName" FROM "File" WHERE ("File"."ID" IN (\r\n\r\n43925)) ORDER BY "SortOrder" ASC | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\r\n\r\n43925)) ORDER BY "SortOrder" ASC' at line 1,256)
line 123 of MySQLDatabase.php

MySQLDatabase->query(SELECT "File"."ClassName", "File"."Created", "File"."LastEdited", "File"."Name", "File"."Title", "File"."Filename", "File"."Content", "File"."Sort", "File"."ShowInSearch", "File"."SortOrder", "File"."ParentID", "File"."OwnerID", "File"."ID", CASE WHEN "File"."ClassName" IS NOT NULL THEN "File"."ClassName" ELSE 'File' END AS "RecordClassName" FROM "File" WHERE ("File"."ID" IN (\r\n\r\n43925)) ORDER BY "SortOrder" ASC,256)
line 129 of DB.php

DB::query(SELECT "File"."ClassName", "File"."Created", "File"."LastEdited", "File"."Name", "File"."Title", "File"."Filename", "File"."Content", "File"."Sort", "File"."ShowInSearch", "File"."SortOrder", "File"."ParentID", "File"."OwnerID", "File"."ID", CASE WHEN "File"."ClassName" IS NOT NULL THEN "File"."ClassName" ELSE 'File' END AS "RecordClassName" FROM "File" WHERE ("File"."ID" IN (\r\n\r\n43925)) ORDER BY "SortOrder" ASC,256)
line 404 of SQLQuery.php

SQLQuery->execute()
line 761 of File.php

File->instance_get("File"."ID" IN (\r\n\r\n43925),,,,DataObjectSet)
line 2714 of DataObject.php

DataObject::get(File,"File"."ID" IN (\r\n\r\n43925))
line 161 of MultipleFileUploadField.php

MultipleFileUploadField->Files()
line 369 of ViewableData.php

ViewableData->obj(Files,,,1,)
line 411 of ViewableData.php

ViewableData->cachedCall(Files,)
line 424 of ViewableData.php

ViewableData->hasValue(Files)
line 11 of .cache.uploadify.templates.Includes.AttachedFiles.ss

include(/home/test/public_html/silverstripe-cache/.cache.uploadify.templates.Includes.AttachedFiles.ss)
line 429 of SSViewer.php

SSViewer->process(MultipleImageUploadField)
line 342 of ViewableData.php

ViewableData->renderWith(AttachedFiles)
line 107 of MultipleFileUploadField.php

MultipleFileUploadField->refresh(SS_HTTPRequest)
line 143 of RequestHandler.php

RequestHandler->handleRequest(SS_HTTPRequest)
line 161 of RequestHandler.php

RequestHandler->handleRequest(SS_HTTPRequest)
line 161 of RequestHandler.php

RequestHandler->handleRequest(SS_HTTPRequest)
line 161 of RequestHandler.php

RequestHandler->handleRequest(SS_HTTPRequest)
line 161 of RequestHandler.php

RequestHandler->handleRequest(SS_HTTPRequest)
line 147 of Controller.php

Controller->handleRequest(SS_HTTPRequest)
line 282 of Director.php

Director::handleRequest(SS_HTTPRequest,Session)
line 125 of Director.php

Director::direct(/admin/EditForm/field/GalleryImages/UploadifyForm/field/UploadedFiles/refresh)
line 127 of main.php

</ul>