Uh, bit lost at this point. Still new, and possibly in over my head.
I'm trying to make a nfo/txt to PNG image converter for a website. Have to save the png to disc, and discard any uploaded nfo/txt. I can get it to convert and save a PNG image of text that I put into a text box form fairly easily, but I can't manage to get the uploaded file to work.
Its not just the if statement, even though that is screwed up =.=, as I've totally removed it and this still doesn't work. 🤷
3 Files in total. Bottom one is a modified version of the second one.
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>my php playground</title>
</head><center>
<form enctype="multipart/form-data" action="nfotest.php" mehtod="post">
Foreground color (e.g. 393939): <input type="text" name="color" /><br />
Background color (e.g. 393939): <input type="text" name="back" /><br />
Choose a file to upload: <br /><input name="file" type="file" size="30" /><br />
<p> - or - </p>
Copypasta the nfo:<br /> <textarea cols="50" rows="15" name="nfo"></textarea><br />
<input type="submit" value="Get um!" />
</form></center>
<body>
</body>
</html>
nfotest.php
<?php
$fore = $_REQUEST['color'];
$back = $_REQUEST['back'];
$rand = rand(0,9999999999999);
$filename = "$rand.png";
require_once("nfo2png.php");
if($_FILES['file']['tmp_name']){
$f = file($_FILES['file']['tmp_name']);
$f = implode("",$f);
}
else{
$f = $_REQUEST['nfo'];
}
buildNFO($f, "Powered by : EH3:Board", $fore, $back, $filename, $rand);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<?php
print('<meta HTTP-EQUIV="REFRESH" content="3; url=http://www.eh3.info/nfo/images/' . $filename . '">');
?>
<title>REDIRECT</title>
</head>
<body>
</body>
</html>
nfo2png.php
<?php
/*
* File : nfo2png.php
* Created : 14 March 2004
* By : Stefan Gräfe
*
* NFO2PNG - Small NFO to PNG render library
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
function buildNFO($nfotext, $footer, $fg, $back, $filename, $rand) {
// Write Headers for PNG
// header("Content-Type: image/png");
// header("Content-Disposition: inline; filename=\"$rand.png\"");
if(!strlen($nfotext)) $nfotext = "Empty String submitted.";
$nfo = explode("\n", $nfotext);
// Load the Bitmap-Font
$fnt = imageloadfont("nfo2pngfont");
// Check for empty lines
$fillers = strlen($nfo[1])+strlen($nfo[3])+strlen($nfo[5])+strlen($nfo[7])<9?1:0;
$nxo = array();
$xmax = 0;
// Reformat each line
foreach($nfo as $key=>$line){
$line = chop($line);
if($xmax < strlen($line)) $xmax = strlen($line);
if($fillers and ($key & 1)) continue;
array_push($nxo,$line);
}
// Show footer
if(strlen($footer)) {
array_push($nxo,"");
$fill = str_repeat(" ",($xmax - strlen($footer)>>1));
array_push($nxo,$fill.$footer);
}
// Linecount
$ymax = count($nxo);
// Set foreground color
$color = array(0, 0, 0);
if(strlen($fg) == 6) {
$color[0] = intval(substr($fg,0,2), 16);
$color[1] = intval(substr($fg,2,2), 16);
$color[2] = intval(substr($fg,4,2), 16);
}
// Set Background color
$bgcolor = array(0, 0, 0);
if(strlen($back) == 6) {
$bgcolor[0] = intval(substr($back,0,2), 16);
$bgcolor[1] = intval(substr($back,2,2), 16);
$bgcolor[2] = intval(substr($back,4,2), 16);
}
// Render NFO
$im = ImageCreate($xmax*8,$ymax*16);
ImageInterlace($im,1);
$background_color = imagecolorallocate($im, $bgcolor[0], $bgcolor[1], $bgcolor[2]);
$text_color = ImageColorAllocate ($im, $color[0], $color[1], $color[2]);
foreach($nxo as $y=>$line)
ImageString($im, $fnt, 0, $y*16, $line, $text_color);
ImagePNG($im, "images/$filename", 0, PNG_NO_FILTER);
}
?>
Modified nfotest.php >
<?php
$fore = $_REQUEST['color'];
$back = $_REQUEST['back'];
$rand = rand(0,9999999999999);
$filename = "$rand.png";
require_once("nfo2png.php");
$location = basename( $_FILES['file']['name']);
move_uploaded_file($_FILES['file']['tmp_name'], $location);
$f = file($location);
$f = implode("",$f);
buildNFO($f, "Powered by : EH3:Board", $fore, $back, $filename, $rand);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<?php
print('<meta HTTP-EQUIV="REFRESH" content="3; url=http://www.eh3.info/nfo/images/' . $filename . '">');
?>
<title>REDIRECT</title>
</head>
<body>
</body>
</html>
Errors i get from this modified nfotest.php :
[03-Feb-2010 10:27:07] PHP Warning: file() [<a href='function.file'>function.file</a>]: Filename cannot be empty in /*/nfotest.php on line 9
[03-Feb-2010 10:27:07] PHP Warning: implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed in /*/nfotest.php on line 10
Also, I've tried adding both a "/" and a "./" to the $location and again to the file() to try to make the location proper, as someone suggested on a different forum, with no luck. Hopefully someone has a solution. Thanks guys!