Attachments: Still struggling.

"Steven J. Sobol" <[email protected]> Wed, 9 Apr 2003 20:18:50 -0400 (EDT)
Newsgroups gmane.comp.web.midgard.user,gmane.comp.cms.aegir.devel
Message-ID <[email protected]>
I have gained clue by picking apart the code in the image_upload snippet 
from Aegir. I don't have a solution yet, but I'm further along than I was.

When I upload an attachment, I get two messages. One is 

Failed to create attachment - Reason:Name exists

When the call to createattachment() fails, the snippet attempts to 
overwrite the attachment, under the assumption that it already exists. 
Then I get this message.

Failed to overwrite attachment - Reason:Name exists

The "Name exists" messages aren't coming from Aegir, they're coming from 
Midgard; best I can tell is that it is coming from attachment.c in the 
Midgard PHP extension.

My assessment: createattachment() apparently gets far enough to 
create a zero-byte file in the /var/www/blobs-staging directory. 
However, because an error has occurred, the PHP variable that normally 
would represent the attachment object is empty; therefore, the remaining 
chunk of code fails and nothing is actually written into the file in the 
blobs directory.

So, that is one mystery solved. The next mystery is why Midgard is 
insisting "name exists" when I know full well that it doesn't; I can check 
the blobs table in the staging database and see that no records exist with 
the 'name' field set to the name of the file I'm uploading.

An other interesting point: I yanked a chunk of the code out of the 
snippet and customized it. I was just curious if I could get an attachment 
added outside of Aegir. The following code resulted in an ACCESS DENIED 
message. Keep in mind that permissions *are* set so that Apache can read 
and write to the blobs directory - in fact, the aforementioned zero-byte 
file is created in that directory each time I try to upload the file 
through Aegir.

<?

  $result = fopen( "/home/sjsobol/sobol.gif", "r" );
  $file = fread( $result, 200000);
  fclose( $result );

  $page=mgd_get_page(88);

  $att = $page->createattachment("qwe.gif","qwe.gif","image/gif");
  if (mgd_errstr()!="MGD_ERR_OK")
  {
    echo mgd_errstr();
    exit;
  }
  $attobj = mgd_get_attachment($att);
  $attobj->parameter('size', 'x', 750);
  $attobj->parameter('size', 'y', 500);
  $attobj->parameter('size', 'bytes', 11223);
  $attobj->parameter('size', 'mimetype', 'image/gif');
  $filehandle = mgd_open_attachment($att);
  fputs($filehandle, $filename,$$sizename);
  fclose($filehandle);

?>

-- 
Steve Sobol/CTO/JustThe.net LLC/Mentor On The Lake (Cleveland), OH/888.480.4NET
"This country has a strong ethical foundation, but... I hesitate to say that 
erosion has set in, but it is clear that more and more of what we are is being
built on sand and not on that foundation."    - G. Waleed Kavalec, in SPAM-L