importune Posted February 3, 2010 Share Posted February 3, 2010 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. 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); } ?> If I wasn't supposed to post the code or something, let me know. Thanks guys. x.x Link to comment https://forums.phpfreaks.com/topic/190765-basic-upload-conversion-script/ Share on other sites More sharing options...
jammesz Posted February 3, 2010 Share Posted February 3, 2010 i am pretty sure that you need to use move_uploaded_file() function before using the uploaded file to convert to png Link to comment https://forums.phpfreaks.com/topic/190765-basic-upload-conversion-script/#findComment-1005982 Share on other sites More sharing options...
importune Posted February 3, 2010 Author Share Posted February 3, 2010 i am pretty sure that you need to use move_uploaded_file() function before using the uploaded file to convert to png Thanks for the quick response, and for taking the time to read my mess . I have tried this, and it still didn't work. I believe it has something to do with my need to call the file before i have its actual filename, as when i use the FILES array in the file() field, it usually fails. I tried to save it to the server and then delete it at the end of the PNG generation, but it still didn't work. I get just about the same error, even when the file is successfully saved to the server. Anyway- i'd like to accomplish this without having anything other than the final pngs actually saved. Any ideas? :\ EDIT: Btw, this is what i've also tried with no luck-> <?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 : [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 EDIT: I just tested it and still get the same errors even if i change this: $f = file($location); to this: $f = file("$location"); Link to comment https://forums.phpfreaks.com/topic/190765-basic-upload-conversion-script/#findComment-1005987 Share on other sites More sharing options...
jammesz Posted February 3, 2010 Share Posted February 3, 2010 your location $location = basename( $_FILES['file']['name']); isn't a proper location (its just a filename). it should at least have './' or '/' before basename( $_FILES['file']['name']). Also check your file permissions etc. Im not really sure what the problem is but just hoping this may help. Link to comment https://forums.phpfreaks.com/topic/190765-basic-upload-conversion-script/#findComment-1005991 Share on other sites More sharing options...
importune Posted February 3, 2010 Author Share Posted February 3, 2010 Yeah, I've searched the net for like 6 different basic php upload scripts, they all show a location just like this. I don't want it to go into a different directory or anything, just right there is fine, as when I'm done i'm going to delete the file anyway... :| I donno dude, thanks for taking a look, hopefully someone has an answer. Link to comment https://forums.phpfreaks.com/topic/190765-basic-upload-conversion-script/#findComment-1006194 Share on other sites More sharing options...
importune Posted February 3, 2010 Author Share Posted February 3, 2010 Is it even possible to file() the $_FILES array? I can't find anything :-\ Link to comment https://forums.phpfreaks.com/topic/190765-basic-upload-conversion-script/#findComment-1006223 Share on other sites More sharing options...
importune Posted February 3, 2010 Author Share Posted February 3, 2010 An update: I've tried adding the "./" or the "/" multiple ways to both the $location and to the file(). Neither are working. Still says empty string. Link to comment https://forums.phpfreaks.com/topic/190765-basic-upload-conversion-script/#findComment-1006266 Share on other sites More sharing options...
jammesz Posted February 4, 2010 Share Posted February 4, 2010 The error message says that $location is empty or doesnt contain a filename and only a directory. So your problem has something todo with that. Link to comment https://forums.phpfreaks.com/topic/190765-basic-upload-conversion-script/#findComment-1006599 Share on other sites More sharing options...
importune Posted February 4, 2010 Author Share Posted February 4, 2010 Lol, figured it out mates. Typo in my html. x.x Link to comment https://forums.phpfreaks.com/topic/190765-basic-upload-conversion-script/#findComment-1006772 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.