Thursday 29 May 2008

testing for File with file_exists

in my code I have a check to see if there is a thumbnail image if not I then resize the image and make a thumbnail. Before running I need to check that I have a big image to crop in the first place.
I do this with
if (!file_exists($thumbnailImg) && file_exists($imgFull))

however the argument file_exists($imgFull) comes back as TRUE even if the folder exists.
one way to get around this problem would be on the command

$imgFull = $pathFull.$img1;
I could check on $img and if it doesn't exist fill it with a value that deliberatly gives an error

if (strlen($img1) > 4){ // counts that $img1 has more than 4 characters ie 1.gif has 5

$imgFull = $pathFull.$img1;}
else
{$imgFull = $pathFull.'error.txt';}


you can check this code working at self catering cornwall .biz

Tuesday 27 May 2008

Improving listings for HillsideGlastonbury.co.uk

Hillside Glastonbury.

Earlier this month I did some general maintenance work for Hillside Glastonbury B&b and Self Catering . As well as adding lightview image viewer so to make the viewing of images clearer and easier ( to see the effect check Primrose Cottage and click on the main image) I also added several features in the hope we would get the site a better listing with Google.


The idea was to intergrate the site with Googles applications more - There is a list of Google Business tools at Google Services. On this occasion I have added Google Search of Hillside Glastonbury, Google Map of Hillside, Ashwell Lane, Glastonbury, Somerset, BA6 8BG, Hillside Glastonbury Blog and Google Anayltics for accurate stats on our listing with them.


Friday 9 May 2008

Oscommerce Adding a dropdown menu selector to catergories.php

This is a small section of a contribution that I am writing to add to the website
www.surfboardsuperstore.co.uk

The site is made with oscommerce. The problem I had was this

///////////////////FORUM///////////////////////////////////////////////////

I'm trying to write a contribution that includes adding extra value to my product tables.

I can get the code to work with an input field - but would ideally like to change this to a dropdown list. The code that is in question is



CODE





surferRecWeight); ?>




so instead of using tep_draw_input_field - i would like to use tep_draw_pull_down_menu. I know that the second arguement for the function tep_draw_pull_down_menu needs to be my array for the drop list. I have tried a couple of different ways to make the array ie


CODE
$ability_array = array('Expert', 'Average', 'Novice');


OR


CODE
$ability_array = array(0 => 'Expert', 1 => 'Average', 2 => 'Novice');


OR


CODE
$ability_array[0] ='Expert';
$ability_array[1] = 'Average';
$ability_array[2] = 'Novice';


either way I get the same result which is that the drop down list only has the first letter of my array element - 'e','a',' & 'n'.

does anyone know why. I know that the function allows strings more than one character ?



the code I am using to call up the function is



CODE
echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_pull_down_menu('surferRecAbility', $ability_array, $pInfo->surferRecAbility);

///////////////////END OF FORUM ENTRY//////////////////////////////


A very odd problem indeed, To solve this i wrote a hack ( probably very ugly) - after following the trail of the problem here the function that I needed to change was in admin/includes/functions/html_output.php and the function in question was tep_draw_pull_down_menu. so instead of messing this function up, after all every other pull down menu in admin seems to work fine! I created a new one. which is as follows

[code]

function tep_draw_pull_down_menu_two($name, $values, $default = '', $parameters = '', $required = false) {
$field = '';

if ($required == true) $field .= TEXT_FIELD_REQUIRED;

return $field;
}

[/code]

the only changes here are in $values[$i]. this is a much simplified version of what was there before, I take it because I created an array without keys etc that this is why it never worked. another solution therefore would be to rewrite the array in a format in keeping with oscommerce. However due to time constraints I will push on with the ugly hack ;)

Thursday 1 May 2008

Making sure that theres no gaps in the filenames of image uploads.

The problem that needed to solved here was that users could upload there own images - and if the filename they were uploading has gaps or whitespace.
It took me a while to get my head around this one, eventhough the solution is fairly simple.
If you have solving the same problem here are a couple of links that may help. Firstly I posted this problem on a developer network forum. you can see that post at http://forums.devnetwork.net/viewtopic.php?f=1&t=82057 .
A tutorial that helps understand how file upload works in php is http://www.tizag.com/phpT/fileupload.php.

Any back to my code.

What I needed to do first was check to check if theres any spaces and replace with '_'

[code]
$img1 = str_replace ( ' ', '_', $img1 );

[/code]

then in move_uploaded_file change it to

[code]
$res = move_uploaded_file($_FILES['img1']['tmp_name'], $abpath .
$img1);
[/code]


staright forward, I have no idea now why I couldn't get my head around this straight away.