Im trying to follow
to create thumbnails
And my variables dont seem to be seen by t he createThumbnails(), heres the page
<?php
session_start();
//change variable depending if form has been submitted
if(isset($_FILES['image'])) {
$providerID = $_POST['id'];
} else {
$providerID = $_GET['id'];
}
require '../providers/config.php';
require '../providers/functions.php';
?>
....(HTML)
<?php
//if form has been submitted
if(isset($_FILES['image'])) {
echo $path_to_image_directory." ; ".$path_to_thumbs_directory;
if(preg_match('/[.](jpg)|(gif)|(png)|(bmp)$/', $_FILES['image']['name'])) {
$filename = $_FILES['image']['name'];
$source = $_FILES['image']['tmp_name'];
$target = $path_to_image_directory . $filename;
move_uploaded_file($source, $target);
createThumbnail($filename);
}
} else {
?>
...(form)
<?php
}
?>
...
The config file holds 3 variables
<?php
$final_width_of_image = 200;
$path_to_image_directory = "../providers/{$providerID}/";
$path_to_thumbs_directory = "../providers/{$providerID}/thumbs/";
?>
the functions file has the function
<?php
function createThumbnail($filename) {
require 'config.php';
if(preg_match('/[.](jpg)$/', $filename)) {
$im = imagecreatefromjpeg($path_to_image_directory . $filename);
} else if (preg_match('/[.](gif)$/', $filename)) {
$im = imagecreatefromgif($path_to_image_directory . $filename);
} else if (preg_match('/[.](png)$/', $filename)) {
$im = imagecreatefrompng($path_to_image_directory . $filename);
} else {
$im = imagecreatefromwbmp($path_to_image_directory . $filename);
}
$ox = imagesx($im);
$oy = imagesy($im);
$nx = $final_width_of_image;
$ny = floor($oy * ($final_width_of_image / $ox));
$nm = imagecreatetruecolor($nx, $ny);
imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);
imagejpeg($nm, $path_to_thumbs_directory . $filename);
$tn = '<img src="' . $path_to_thumbs_directory . $filename . '" alt="image" />';
echo $tn;
}
?>
If I go to the page, submit the form, I get
I looked at the src of the image
../providers//thumbs/1929035_1034297219327_4546015_n.jpg
So why cant the function see the variable like the page can?