PDA

View Full Version : PHP Question


creek
1-15-02, 12:38 AM
Okay, I managed to get my script working by doing the following:

My script index.php3 calls another script, nailcut.php3 with the line
include("nailcut.php3");
at the end of the script.

Seems the script does NOT work when I use the two files but when I take the contents of the second file and paste it into the 1st file so as having everything in one file instead of two, my script runs fine. Can you tell me why this is? I am not a programmer this is a script I downloaded off the net and it worked fine in it's original format on the server I was using before I switched to powweb.

Thanks for letting me know why this might be happening as I may want to use other php scripts that use multiple files and I may not be able to edit them in the same way. (as I mentioned I'm not a programmer)

esccanada
1-15-02, 12:14 PM
Check to make sure that both files have the correct permissions.

They both should be 755 (CHMOD).

How to set this depends on what package you are using to upload the files.

Check in the FAQs for information on these settings.

jbenalluch
1-15-02, 12:15 PM
have you added to both files the line (i hate that line soooooo much) #!/usr/local/bin/php
to the top of each file, and uploaded them in ASCII mode and changed the mode of each file to 755?

if you did, i don't know what the problem is... i think the the CGI version of PHP sucks badly

sophiespo
1-15-02, 12:32 PM
you DONT need to add the #!/usr/local/bin/php line to a file thats being included!!!!!!!!! itll just make it say #!/usr/local/bin/php at the top of the page and screw up any cookies you are trying to use...

if a file ISNT being called directly, i.e. if the url of the file is NEVER in the address box at the top of your browser, then you dont need the line. Confusing, yes, but after a while you get used to it.
You can tell when files are included when you see this line in your code:
include("filename.php") <-- filename.php doesnt need the line at the top.

sophie

creek
1-15-02, 09:35 PM
I uploaded both files using WSFTP in ASCII and chmod 755. I tried with that added line on both files and with it only on the one file. Didn't matter either way. It doesn't work either way! It doesn't work with the additional file.

I agree, this cgi-php sucks! This script worked great with no hitch on the server I had before I moved here.

Any other ideas would be appreciated!

Here is the 1st file:

#!/usr/local/bin/php
<?php
//directory with original pics
$img_dir = "pics/";
//directory for thumbnail files
$thumbs_dir = "mpics/";
//thumbnail template
$borderpic = "thumb.png";
//spacing between template size and thumbnail size
$thumbsborder = 10;
//thumbnails in one row
$columns = 4;
//thumbnails on one page
$maxperpage = 12;
//htmlcode around
$templatefile = "template.html";
//save generated thumbnails? faster!
$save = true;
//regular expression for filemask
// ".+\.png$|.+\.jpg$" = all .png and .jpg
// ".+\.jp[e]{0,1}g$" = all .jpeg and .jpg
// ".+\.gif" = all .gif
$ext_pattern = ".+\.jp[e]{0,1}g$";
//caption of thumbnail table
$infocaption = "Photo Gallery";
//link to previous page
$prevcaption = "Previous";
//link to next page
$nextcaption = "Next";

include("nailcut.php3");
?>


And here is the second file:

<?php
function thumb_getsize($thumb_width,$thumb_height,$original _width,$original_height,$border=0) {
$min_width = $thumb_width - $border - $border;
$min_height = $thumb_height - $border - $border;
$div_width = $original_width / $min_width;
$div_height = $original_height / $min_height;
if ($div_width >= $div_height) {
$res_width = $min_width;
$res_height = round($original_height / $div_width);
$res_left = $border;
$res_top = round(($min_height / 2) - ($res_height / 2) + $border);
} else {
$res_height = $min_height;
$res_width = round($original_width / $div_height);
$res_top = $border;
$res_left = round(($min_width / 2) - ($res_width / 2) + $border);
}
$result = array($res_left,$res_top,$res_width,$res_height);
return $result;
}
function thumb_create($original_img,$img_border,$rect,$orig inal_width,$original_height,$border_width,$border_ height) {
$thumbnail = imagecreate($border_width,$border_height);
imagecopyresized($thumbnail,$img_border,0,0,0,0,$b order_width,$border_height,$border_width,$border_h eight);
imagecopyresized($thumbnail,$original_img,$rect[0],$rect[1],0,0,$rect[2],$rect[3],$original_width,$original_height);
return $thumbnail;
}
function thumb_print($dir,$file_thumb,$file_border,$s,$f,$m dir) {

if ($f or (!(file_exists($mdir.$file_thumb)))) {
list($width,$height,$pictype) = getimagesize($dir.$file_thumb);
switch ($pictype) {
case 1 : $img = imagecreatefromgif($dir.$file_thumb); break;
case 2 : $img = imagecreatefromjpeg($dir.$file_thumb); break;
case 3 : $img = imagecreatefrompng($dir.$file_thumb); break;
}
list($b_width,$b_height,$b_pictype) = getimagesize($file_border);
switch ($b_pictype) {
case 1 : $imgborder = imagecreatefromgif($file_border); break;
case 2 : $imgborder = imagecreatefromjpeg($file_border); break;
case 3 : $imgborder = imagecreatefrompng($file_border); break;
}
if (($img) && ($imgborder)) {
$rect = thumb_getsize($b_width,$b_height,$width,$height,$G LOBALS["thumbsborder"]);
$thumbnail = thumb_create($img,$imgborder,$rect,$width,$height, $b_width,$b_height);
if ($s) {
switch ($pictype) {
case 1 : imagegif($thumbnail,$mdir.$file_thumb); break;
case 2 : imagejpeg($thumbnail,$mdir.$file_thumb); break;
case 3 : imagepng($thumbnail,$mdir.$file_thumb); break;
}
}
switch ($pictype) {
case 1 : imagegif($thumbnail); break;
case 2 : imagejpeg($thumbnail); break;
case 3 : imagepng($thumbnail); break;
}
}
} else {
list(,,$pictype) = getimagesize($mdir.$file_thumb);
switch ($pictype) {
case 1 : $img = imagecreatefromgif($mdir.$file_thumb); break;
case 2 : $img = imagecreatefromjpeg($mdir.$file_thumb); break;
case 3 : $img = imagecreatefrompng($mdir.$file_thumb); break;
}
switch ($pictype) {
case 1 : imagegif($img); break;
case 2 : imagejpeg($img); break;
case 3 : imagepng($img); break;
}
}
}
function read_data($data_dir,$ext) {
$dir_handle = @opendir($data_dir);
if ($dir_handle) {
while ($file = readdir($dir_handle)) {
if (eregi($ext,$file)) {
$files[] = $file;
}
}
closedir($dir_handle);
}
if (gettype($files) == "array") {
sort($files);
} else {
$files = false;
}
return $files;
}
function index_print($dir,$ext,$template,$dia,$cols,$f,$max perpage,$start) {
$lines = file($template);
$line = implode("",$lines);
$selflink = $GLOBALS["PHP_SELF"];
$images = read_data($dir,$ext);
if ($images) {
list(,,,$sizestr) = getimagesize($dia);
$table = $GLOBALS["infocaption"]."<br><br><table border=\"0\" cellpadding=\"2\">\r\n<tr>";
$max = count($images)-1;
$end = $start+$maxperpage-1;
$counter = 0;
while (list($key,$image) = each($images)) {
if (($key >= $start) && ($key <= $end)) {
$piclink = $PHP_SELF."?cmd=min&pic=".$image;
if ($f) {$piclink .= "&f=1"; }
$biglink = $PHP_SELF."?cmd=max&start=".$start."&pic=".$image;
$table .= "<td><a href=\"$biglink\"><img src=\"$piclink\" border=\"0\" $sizestr></a></td>";
$counter++;
if (((($counter) % $cols) == 0) && ($key < $end)) {
$table .= "</tr><tr>";
}
}
}
$table .= "</tr></table>";
if ($start > 0) {
$prevstart = $start - $maxperpage;
$table .= "<a href=\"$selflink?start=$prevstart\">".$GLOBALS["prevcaption"]."</a>&nbsp;&nbsp;&nbsp;";
}
if ($end < $max) {
$nextstart = $end+1;
$table .= "<a href=\"$selflink?start=$nextstart\">".$GLOBALS["nextcaption"]."</a>";
}
} else {
$table = "No files in <b>$dir</b>";
}
$line = str_replace("###pictable###",$table,$line);
return $line;
}
function image_print($pic,$template,$start) {
$lines = file($template);
$line = implode("",$lines);
$selflink = $GLOBALS["PHP_SELF"];
list(,,,$sizestr) = getimagesize($pic);
$piclink = "<img src=\"$pic\" border=\"0\" $sizestr><br><br>";
$piclink .= "<a href=\"$selflink?start=$start\">Back</a>";
$line = str_replace("###pictable###",$piclink,$line);
return $line;
}
function main($cmd,$dir,$pic,$dia,$template,$cols,$s,$f,$md ir,$maxperpage,$start,$ext=".png") {
switch ($cmd) {
case "min" :
thumb_print($dir,$pic,$dia,$s,$f,$mdir);
break;
case "max" :
echo image_print($dir.$pic,$template,$start);
break;
default :
echo index_print($dir,$ext,$template,$dia,$cols,$f,$max perpage,$start);
}
}
main($cmd,$img_dir,$pic,$borderpic,$templatefile,$ columns,$save,$f,$thumbs_dir,$maxperpage,$start,$e xt_pattern);
?>


Sorry this is so long, but I really want to know why this isn't working.

Thanks.