We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

File

Development and Programming

funnEE's avatar
funnEE
93 posts
18 years ago
funnEE's avatar funnEE

Ok. I was getting errors because the variables I was using were not defined in core.functions.php I have gone away from using variables for the <a> record and just implemented Mark’s code and it works for only one entry. I also tried to wrap my own <a> record around it, but when I do outside the php, the file name seem to disappear. And if the array worked for more than one entry the <a> records won’t. Any ideas? Thanks

       
funnEE's avatar
funnEE
93 posts
18 years ago
funnEE's avatar funnEE

For the SAEF problem, I am getting a

MySQL ERROR:

Error Number: 1054

Description: Unknown column 'field_id_1_img' in 'field list'

Thanks for any help

       
mhulse's avatar
mhulse
329 posts
18 years ago
mhulse's avatar mhulse
Ok. I was getting errors because the variables I was using were not defined in core.functions.php

When I get those errors, I usually look at the PHP I have on the template… It kinda sounds like the PHP code you have implemented on the template page is funky, not core.functions.php.

I have gone away from using variables for the <a> record and just implemented Mark’s code and it works for only one entry. I also tried to wrap my own <a> record around it, but when I do outside the php, the file name seem to disappear. And if the array worked for more than one entry the <a> records won’t. Any ideas? Thanks

I quickly wrote this function:

function get_file($x) {
    if(!empty($x)) {
        $cust = $x; // Name of custom field.
        $parts = explode(',', $cust) // array of file name
        $junk = array_pop($parts) // Get rid of last key.
        foreach($parts as $part) { // Loop through array and echo results.
            $filename = basename($part) // name of file with extension.
            $result = explode('.', $filename) // $result[0] = file name, $result[1] = extension.
            echo 'File name without extension: '.$result[0].' (ext: '.$result[1].')'."\n"; // You could add to, and return an array of values.
        }
    } else { echo 'Error: Make sure you uploaded files.'; }
}

EDIT: Forum is messing with my code! Stupid html entities!

I put that in a file called functions.inc.php and put in a folder called “includes” on my server root.

Then, at the top of my template, I call the above file like so:

<?php
$doc_root = $_SERVER['DOCUMENT_ROOT'];
include($doc_root.'/includes/functions.inc.php')
...
...
// Other PHP includes and such here.
...
...
?>

Then on my template prefs, I allow PHP and set the “PHP Parsing Stage” to “output”.

Next, within my weblog entries tag, I call the function like so:

<?php get_file('{article_images}{article_image},{/article_images}') ?>

(Note: Notice the comma?)

Above code will produce this:


File name without extension: wtf (ext: jpg)
File name without extension: wtf_1 (ext: jpg)
File name without extension: rightquote (ext: gif)
File name without extension: leftquote (ext: gif)

I hope that helps… The function could be more robust and do other things… Maybe a bit more secure and few more error checking features? Also, working with PHP on INPUT might make things easier – Test it out for yourself. ;)

Hth’s. Micky

EDIT/UPDATE: Hmm, looks like setting the PHP Parsing Stage to INPUT makes no difference when it comes to the list of files (I was hoping I could get an array of files straight from the File Extension)… Below, I set my template to allow PHP with the PHP Parsing Stage set to INPUT:

function get_file2($x) {
    if(!empty($x)) {
        $cust = $x; // Name of custom field.
        print_r($cust); // Does PHP set to input make a difference? Will it give us an array vs. a string?
    } else { echo 'Error: Make sure you uploaded files.'; }
}
...
<html stuff>
...
<?php get_file2('{article_images}{article_image}{/article_images}'); ?>
...

The output:

http://www.mysite.com/images/articles/wtf.jpghttp://www.mysite.com/images/articles/wtf_1.jpghttp://www.mysite.com/images/articles/rightquote.gifhttp://www.mysite.com/images/articles/leftquote.gif
       
mhulse's avatar
mhulse
329 posts
18 years ago
mhulse's avatar mhulse

FYI… This also works (PHP on, and Parsing set to OUTPUT):

<?php
function get_file2($x) {
    if(!empty($x)) {
        foreach($x as $part) { // Loop through array and echo results.
            $filename = basename($part); // name of file with extension.
            $result = explode('.', $filename); // $result[0] = file name, $result[1] = extension.
            echo 'File name without extension: '.$result[0].' (ext: '.$result[1].')'."\n"; // You could add to, and return an array of values.
        }
    } else { echo 'Error: Make sure you uploaded files.'; }
}
?>
...
..<template>...
..<template>...
...
{exp:weblog:entries}
<?php $hldr = array(); // Initialize array. ?>
{article_images}<?php $hldr[] .= '{article_image}'; ?>{/article_images}
<?php get_file2($hldr); ?>
{/exp:weblog:entries}

Outputs this:

File name without extension: wtf (ext: jpg)
File name without extension: wtf_1 (ext: jpg)
File name without extension: rightquote (ext: gif)
File name without extension: leftquote (ext: gif)

EDIT: Even more simple of an approach (with same template settings as above):

function get_file3($x) {
        $filename = basename($x); // name of file with extension.
        $result = explode('.', $filename); // $result[0] = file name, $result[1] = extension.
        echo 'File name without extension: '.$result[0].' (ext: '.$result[1].')'."\n";
}
...
..<template>...
..<template>...
...
{exp:weblog:entries}
{article_images}<?php get_file3('{article_image}'); ?>{/article_images}
{/exp:weblog:entries}
       
funnEE's avatar
funnEE
93 posts
18 years ago
funnEE's avatar funnEE

Dear Wild Garden, Thanks so much, I implemented the EDIT approach and it works perfectly. Yep, my php code was causing the errors, not functions.php. I forgot to include the \ infront of each ” in my <a> record. Regardless, your solution is perfect for me. Thanks so much. D

       
funnEE's avatar
funnEE
93 posts
18 years ago
funnEE's avatar funnEE

Dear Wild Garden, Thanks so much, I implemented the EDIT approach and it works perfectly. Yep, my php code was causing the errors, not functions.php. I forgot to include the \ in front of each ” in my <a> record. Regardless, your solution is perfect for me. Thanks so much. D [EDIT] Sorry for the repeat

       
funnEE's avatar
funnEE
93 posts
18 years ago
funnEE's avatar funnEE
MySQL ERROR:

Error Number: 1054

Description: Unknown column 'field_id_1_img' in 'field list'

Is any body else getting SQL errors with ‘_img’ using SAEF? The query: INSERT INTO, is trying to insert into a custom field name with _img . The _img should be removed in the extension. When publishing from the control panel, everything works fine.

[EDIT] I followed the advice before on just copying the html (and JS addrows) from the CP publish page. But forgot to edit mod.weblog_standalone.php. I’m sorry for not looking deep enough. Thanks so much Mark.

       
Adam George's avatar
Adam George
283 posts
18 years ago
Adam George's avatar Adam George

This is what shows up when I try to use this extension:

{multi_relatedfiles}{multi_relatedfiles}{/multi_relatedfiles}

This is my template src:

{multi_relatedfiles}<a href="http://{multi_relatedfiles}">{multi_relatedfiles}</a>{/multi_relatedfiles}

My field name is ‘relatedfiles’. I have multiple files enabled in the extension settings. I have re-enabled the extension, checked file upload paths, and fixed the warning notice as advised.

Any idea as to why it’s not showing up?

       
mhulse's avatar
mhulse
329 posts
18 years ago
mhulse's avatar mhulse

Hi, try this:

{relatedfiless}<a href="http://{relatedfiles}">{relatedfiles}</a>{/relatedfiless}

EDIT: The extension got changed from “multi_” to making the “wrapper” tags plural. Example using Custom File Field with Field Name of “file”:

{files}{file}{/files}
       
Adam George's avatar
Adam George
283 posts
18 years ago
Adam George's avatar Adam George

Hmmm, thanks Wild Garden, however when I try that:

{relatedfiles}<a href="http://{relatedfile}">{relatedfile}</a>{/relatedfiles}

All I get is this:

http://www.tear.org.au.php5-1.websitetestlink.com/uploads/resources/0{relatedfile}{/relatedfiles}

And the source code shows this:

http://www.tear.org.au.php5-1.websitetestlink.com/uploads/resources/0<a href="http://{relatedfile}">{relatedfile}</a>{/relatedfiles}

Weird?

Also, I don’t suppose there is a way to test if the field is not empty?

TY

       
mhulse's avatar
mhulse
329 posts
18 years ago
mhulse's avatar mhulse
Weird?

Yah, because when I do this on my template:

{article_images}<a href="http://{article_image}">{article_image}</a>{/article_images}

It works just fine. :: scratches head ::

       
mhulse's avatar
mhulse
329 posts
18 years ago
mhulse's avatar mhulse
Also, I don’t suppose there is a way to test if the field is not empty?

I just had a chance to test, and these work for me (using a multiple upload file field):

{if article_image}
<div id="articleImage">
...code here...
</div>
{/if}
{if article_image != ""}
<div id="articleImage">
...code here...
</div>
{/if}
       
Scheffey's avatar
Scheffey
24 posts
18 years ago
Scheffey's avatar Scheffey

First, kudos to Mark…great extension (makes life easy on the clients)…thank you!

Second, I can’t seem to troubleshoot this error:

Warning: getimagesize(): open_basedir restriction in effect. File(/tmp/phpAVqzh4) is not within the allowed path(s): (/vservers/hlwiker) in /vservers/hlwiker/htdocs/system/extensions/ext.file.php on line 492

Warning: getimagesize(/tmp/phpAVqzh4): failed to open stream: Operation not permitted in /vservers/hlwiker/htdocs/system/extensions/ext.file.php on line 492

Warning: Cannot modify header information - headers already sent by (output started at /vservers/hlwiker/htdocs/system/extensions/ext.file.php:492) in /vservers/hlwiker/htdocs/system/core/core.functions.php on line 710

Have you (or anyone) seen this. Thoughs? Suggestions?

This error occurs after I upload an image and submit the entry changes.

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

It looks like php safe mode is turned on, which isn’t allowing you to upload files. I’ve had this problem before and am looking into a workaround for the next version, however in the meantime should probably ask your host why the /tmp director isn’t writeable.

       
Scheffey's avatar
Scheffey
24 posts
18 years ago
Scheffey's avatar Scheffey

Mark,

Thanks for responding. I checked with the hosting provider. We turned safe mode off and set the tmp directory settings to 777. Still no luck.

However, I had one of the techs at the hosting facility try uploading a file from their location….and no errors?

Thoughts?

       
First 8 9 10 11 12 Last

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.