Link to file stored in database

ak613 08 Jul, 2015
Hi,

I am using Chronoforms and Chronoconnectivity to add and show entries in a previously created database. The database was created on a different system, and one of the columns hold images. I want to display the images using chronoconnectivity, but I can't figure out how to do that. When I look at the connection settings, it asks for the absolute path to the image, which I don't know because the image is in a database folder.
I also need to be able to upload the actual image (not just the file name) into the database table so the new file uploads will be in the same place as the old ones. Is there a way to do that?

Thanks,
AK
GreyHead 09 Jul, 2015
Hi AK,

In theory this should be possible - I remember a similar question with CFv4 a couple of years ago. I experimented a bit but was never successful in getting images in and out of database tables :-( I still think that it should be possible in CF using Custom code; I'm not so sure about recovering them in CC though.

Bob
ak613 10 Jul, 2015
Hi Bob,

Ok, so I've actually managed to get it to display thumbnails (that already existed in the db) of the images and to link to the actual images using some php code with ChronoConnectivity.

Now my problem is getting new images into the db using my chronoform. (I also want to create thumbnails and insert those as well, but I haven't even tried that yet.) Right now the file upload saves the image to the default folder (in com_chronoforms), so I put in a custom code action after the db save to read it in and insert it into the database:

<?php

$link = mysql_connect("localhost", "root", "pass");
mysql_select_db("db_name");

if (! $link) 
{ 
die ('Could not connect: ' . mysql_error()); 
}

$data = file_get_contents('http://host/components/com_chronoforms5/chronoforms/uploads/Upload_Docs/{FILENAME}');


$sql = "INSERT INTO images (IMAGE) VALUES ( '$data' )  where IMAGEID = {id}";

$result = (mysql_query( $sql, $link );

if ($result === TRUE) 
{
echo "Image inserted!";
} 
else 
{
echo "Error: " . $link->error; 
}

mysql_close($link);
?>


Unfortunately, it seems like this code is not running or something, because no matter what I do (like changing it to insert all the data instead of using a db save) it doesn't seem to do anything. I'm sure that the connection to the database works because I used that same piece of code to display the images (pdfs by the way) and that works. I'm also confused why I when I run this I don't see anything indicating it ran in the debugger.

Please help!

Thanks,
AK
ak613 10 Jul, 2015
Just learned that I have to use update instead of insert, so changed it to

$sql = "UPDATE images SET IMAGE = '$data' WHERE IMAGEID = {id}";


Thing is, still nothing happens...

Any ideas??

Thanks,
AK
GreyHead 11 Jul, 2015
Hi Ak,

I think that the {id} may be the problem - you probably need a PHP variable in there, possibly $form->data['id']

Bob
ak613 13 Jul, 2015
Hi Bob,

I just tried changing that and I'm still not getting anything. I was wondering if the problem is that the custom code isn't running at all, so I put an echo statement right after the php tag, and when I submit the form, everything else works but I don't even get that statement. So I'm pretty sure that the biggest problem is that the custom code isn't running at all.
How do I fix this?

Thanks,
AK
GreyHead 13 Jul, 2015
Hi AK,

I can only suggest that you debug your PHP,

Start by commenting out everything except
<?php echo 'xxx'; ?>
to make sure that the action is being executed then add back bit by bit until you find where it fails.

it isn't code that I would write so I can’t make any useful suggestions about it. I don't' see any obvious problems other than the {id} that you have already changed.

Bob
ak613 14 Jul, 2015
Hi Bob,

So I followed your advice and debugged my code. Turns out, the problem was the open parenthesis before the mysql_query!! Well, with that (and a few other minor bug fixes) fixed, it's working.
Just an FYI to anyone else out there is trying to do this, the $form->data['id'] has to be {$form->data['id']}. Also, {FILENAME} has to be {$form->data['FILENAME']}, and the mysql_query should be mysql_query($sql).

Ok, so now I have a totally different question. I'm trying to filter the form using a chronoform which is connected by a link. I used what was suggested in http://www.chronoengine.com/forums/posts/f12/t96289.html, and that works. But now I want to add to it a datepicker so the user can filter by a list of results. I also looked at the post https://www.chronoengine.com/forums/posts/f12/t99087/chrono-connectivity-filtering-by-a-range-of-results.html, but I can't figure out how to combine them so it works. Any ideas?

Thanks!
AK
This topic is locked and no more replies can be posted.