Hi There -

Am having some difficulty with Imagecache and I'm hoping someone can help. I'm bulk uploading images into a directory in files. The filenames are being bulk uploaded from spreadsheets with nodes. Trying to call the image via imagecache.

My issue is that when I create a filepath, Imagecache reads the variable I'm using strangely. Can you help me figure out where I'm going wrong?

Here's my initial code:

<div class="node-image">
<?php
$folder = 'sites/all/files/prototype_images/';
print 'Folder: ' . $folder . '<br />';

$imagename = $node->field_image_bkg_filename[0]['view'];
print 'Filename: '. $imagename . '<br />';

$imagepath = $folder.$imagename;
print 'Imagepath: '.$imagepath . '<br />'; ?>

<div class="imagecache">
<?php print theme('imagecache', 'item', '$imagepath'); ?>
</div>
</div>

Here's the output:

<div class="boutique-node-image">
Folder: sites/all/files/prototype_images/
<br/>
Filename: correct_filename.jpg
<br/>
Imagepath: sites/all/files/correct_filename.jpg
<br/>
<div class="imagecache">
<img class="imagecache imagecache-boutique_item" title="" alt="" src="http://localhost:8888/sites/all/files/imagecache/item/%24imagepath"/>
</div>
</div>
</div>

Note how the path isn't concatenating. How do I do this correctly?

Comments

dman’s picture

That's PHP quotes :-)

print theme('imagecache', 'item', $imagepath);
- no single-quotes - will get you closer.
Double-quotes would also have worked, but single-quotes don't do variable replacements.

Not sure if you may find other issues with what you are trying to do, because storing your filename on its own in $node->field_image_bkg_filename[0]['view'] looks a little flakey. But if it's what you want to do, we can at least get string concatenation to work for you.

newbstah’s picture

Thanks! Worked like a charm.

Need to do several things.
1) We have pretty complicated prototype nodes that other nodes reference with nodereference.
2) We're going to have thousands, so we need to be able to upload many at a time using a spreadsheet and node-import.
3) We were going to have someone upload batches of images with the spreadsheet. On the spreadsheet would be the filename.

Imagefield upload creates single nodes for each image. We're going to have multiple images per node.

I am looking for alternatives and am open to any suggestion if you have one.

Thanks again!

fizk’s picture

Status: Active » Closed (won't fix)