Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 6:32 am
Also it looks like if I change the [] fpr (), I cannot use =>.............. ?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Where? getWidths? Just return array() instead of [].simonmlewis wrote:ahhhhhhhhhhhhh
So for now, how do I edit the $widths to accept it on this server until we update?
Code: Select all
if (isset($resize))
{
if ($resize == "categories" || $resize == "products")
{
// An array of widths, keyed by target screen size
$widths = (
'475' => 237,
'768' => 384,
'1920' => 451,
);
}
elseif ($resize == "wide")
{
// An array of widths, keyed by target screen size
$widths = (
'475' => 237,
'768' => 384,
'1920' => 950,
);
}
elseif ($resize == "desktopslide")
{
// An array of widths, keyed by target screen size
$widths = (
'475' => 475,
'768' => 768,
'1920' => 1920,
);
}
}For assigning values to array keys? Absolutely you can.simonmlewis wrote:Also it looks like if I change the [] fpr (), I cannot use =>.............. ?
Code: Select all
// Returns an array of widths, keyed by target screen size
function getWidths($resize_option)
{
switch($resize_option) {
case 'categories':
case 'products':
case 'stockbanners':
$widths = [
'475' => 237,
'768' => 384,
'1920' => 451,
];
break;
case 'wide':
$widths = [
'475' => 237,
'768' => 384,
'1920' => 950,
];
break;
case 'desktopslide':
$widths = [
'475' => 475,
'768' => 768,
'1920' => 1920,
];
break;
default:
$widths = [];
break;
}
return $widths;
}Code: Select all
// Returns an array of widths, keyed by target screen size
function getWidths($resize_option)
{
switch($resize_option) {
case 'categories':
case 'products':
case 'stockbanners':
$widths = array(
'475' => 237,
'768' => 384,
'1920' => 451,
);
break;
case 'wide':
$widths = array(
'475' => 237,
'768' => 384,
'1920' => 950,
);
break;
case 'desktopslide':
$widths = array(
'475' => 475,
'768' => 768,
'1920' => 1920,
);
break;
default:
$widths = array();
break;
}
return $widths;
}What json files? What's the error? Only json file I'm aware of is composer.json, which should be part of your deploy.simonmlewis wrote:Ok. So the initial errors have gone, but now it is reporting the json files are missing from the "require once" folder.
I'm asking them if they should be installing it for me, as something is missing!
Or maybe I should do a require once to the core location of it.
Code: Select all
// Returns an array of widths, keyed by target screen size
function getWidths($resize_option)
{
switch($resize_option) {
case 'categories':
case 'products':
case 'stockbanners':
$widths = (
'475' => 237,
'768' => 384,
'1920' => 451,
);
break;
case 'wide':
$widths = (
'475' => 237,
'768' => 384,
'1920' => 950,
);
break;
case 'desktopslide':
$widths = (
'475' => 475,
'768' => 768,
'1920' => 1920,
);
break;
case 'thumbnails':
$widths = (
'475' => 237,
'768' => 384,
'1920' => 451,
'2520' => 600,
);
break;
default:
$widths = [];
break;
}
return $widths;
}Oh. Actually there are no json files in vendor, but since 'vendor' is in the require code, I Assume it should be in the live server too.Celauran wrote:What json files? What's the error? Only json file I'm aware of is composer.json, which should be part of your deploy.simonmlewis wrote:Ok. So the initial errors have gone, but now it is reporting the json files are missing from the "require once" folder.
I'm asking them if they should be installing it for me, as something is missing!
Or maybe I should do a require once to the core location of it.
Look at my example above. You can't just use (), you need to use the old array syntax, array().simonmlewis wrote:What about in the function, as it doesn't like this, and it is probably because of $widths[], but it has return $widths at the end.
Can I just remove $widths =[]; ??Code: Select all
// Returns an array of widths, keyed by target screen size function getWidths($resize_option) { switch($resize_option) { case 'categories': case 'products': case 'stockbanners': $widths = ( '475' => 237, '768' => 384, '1920' => 451, ); break; case 'wide': $widths = ( '475' => 237, '768' => 384, '1920' => 950, ); break; case 'desktopslide': $widths = ( '475' => 475, '768' => 768, '1920' => 1920, ); break; case 'thumbnails': $widths = ( '475' => 237, '768' => 384, '1920' => 451, '2520' => 600, ); break; default: $widths = []; break; } return $widths; }
No. Ideally you upload your composer.json and composer.lock files and then runsimonmlewis wrote:Oh. Actually there are no json files in vendor, but since 'vendor' is in the require code, I Assume it should be in the live server too.Celauran wrote:What json files? What's the error? Only json file I'm aware of is composer.json, which should be part of your deploy.simonmlewis wrote:Ok. So the initial errors have gone, but now it is reporting the json files are missing from the "require once" folder.
I'm asking them if they should be installing it for me, as something is missing!
Or maybe I should do a require once to the core location of it.
I can see composer.json in my root. So if I manually upload that to the root of our beta site, do you think it would "find" where the files were installed on the server??
composer install on the server. If that doesn't work, say because you don't have shell access on the server, then you'd need to upload your vendor directory as well.Code: Select all
array_map('unlink', glob("images/pages/$new_filename*.$new_ext"));Code: Select all
// Returns an array of widths, keyed by target screen size
function getWidths($resize_option)
{
switch($resize_option) {
case 'categories':
case 'products':
case 'stockbanners':
$widths = (
'475' => 237,
'768' => 384,
'1920' => 451,
);
break;
case 'wide':
$widths = (
'475' => 237,
'768' => 384,
'1920' => 950,
);
break;
case 'desktopslide':
$widths = (
'475' => 475,
'768' => 768,
'1920' => 1920,
);
break;
case 'thumbnails':
$widths = (
'475' => 237,
'768' => 384,
'1920' => 451,
'2520' => 600,
);
break;
default:
$widths = ();
break;
}
return $widths;
}http://php.net/manual/en/function.glob.phpsimonmlewis wrote:It now doesn't like this:[text] mod_fcgid: stderr: PHP Warning: array_map(): Argument #2 should be an array in /var/www/vhosts/site.co.uk/subdomains/sand.site.co.uk/httpdocs/includes/a_page.inc on line 518, referer: http://sand.site.co.uk/a_page[/text]Code: Select all
array_map('unlink', glob("images/pages/$new_filename*.$new_ext"));
No, see my post here: viewtopic.php?f=1&t=143432&p=707696#p707687simonmlewis wrote:Also within the function, do you mean the $widths should be like this?
Or...Code: Select all
// Returns an array of widths, keyed by target screen size function getWidths($resize_option) { switch($resize_option) { case 'categories': case 'products': case 'stockbanners': $widths = ( '475' => 237, '768' => 384, '1920' => 451, ); break; case 'wide': $widths = ( '475' => 237, '768' => 384, '1920' => 950, ); break; case 'desktopslide': $widths = ( '475' => 475, '768' => 768, '1920' => 1920, ); break; case 'thumbnails': $widths = ( '475' => 237, '768' => 384, '1920' => 451, '2520' => 600, ); break; default: $widths = (); break; } return $widths; }
[syntax]
default:
break;
}
return $widths();
}[/syntax]