Jump to content

Creat, write and change variable through forms


princemac

Recommended Posts

Hi, me again,

 

First I'll show you what I have and then explain my conumdrum.

 

I made the following html code:

<html>
<body>
<form action="addfile.php" method="post">
<p>File Name - <input type="text" name="file_name" />
<p>
<p>Actionshot URL - <input type="text" name="file_contentboxshot" />
<p>
<p>Boxshot URL - <input type="text" name="file_contentactionshot" />
<p>
<p>Rom Number - <input type="text" name="file_contentnumber" />
<p>
<p>Rom Name (First Line) - <input type="text" name="file_contentnamea" />
<p>
<p>Rom Name (Second Line) - <input type="text" name="file_contentnameb" />
<p>
<p>Rom Region - <input type="text" name="file_contentregion" />
<p>
<p>Rom Language - <input type="text" name="file_contentlang" />
<p>
<p>Rom Genre - <input type="text" name="file_contentgenre" />
<p>
<p>File Extension:
<select name="file_ext">
<option value=".txt">Text</option>
</select>
</p>
<p>
<input type="submit" name="submit" value="Submit!" />
</p>
</body>
</html>

 

then i have this php code addfile.php

<?php

if(isset($_POST['submit'])) //has the form been submitted?

{

$file_directory = "./files/"; //the directory you want to store the new file in

$file_name = strip_tags($_POST['file_name']);//the file's name, stripped of any dangerous tags

$file_ext = strip_tags($_POST['file_ext']); //the file's extension, stripped of any dangerous tags

$file_contentactionshot = strip_tags($_POST['file_contentactionshot']); //the file's content, stripped of any dangerous tags

$file_contentboxshot = strip_tags($_POST['file_contentboxshot']); //the file's content, stripped of any dangerous tags

$file_contentnumber = strip_tags($_POST['file_contentnumber']); //the file's content, stripped of any dangerous tags

$file_contentnamea = strip_tags($_POST['file_contentnamea']); //the file's content, stripped of any dangerous tags

$file_contentnameb = strip_tags($_POST['file_contentnameb']); //the file's content, stripped of any dangerous tags

$file_contentregion = strip_tags($_POST['file_contentregion']); //the file's content, stripped of any dangerous tags

$file_contentlang = strip_tags($_POST['file_contentlang']); //the file's content, stripped of any dangerous tags

$file_contentgenre = strip_tags($_POST['file_contentgenre']); //the file's content, stripped of any dangerous tags

$file = $file_directory.$file_name.$file_ext; //this is the entire filename

$create_file = fopen($file, "w+"); //create the new file

$png = file_get_contents("./files/png1.txt");


if(!$create_file)

{

die("There was an error creating/opening the file! Make sure you have the correct permissions!\n");

}

$chmod = chmod($file, 0755); //set the appropriate permissions.

//attempt to set the permissions

if(!$chmod) 

{ 

echo("There was an error changing the permissions of the new file!\n"); //error changing the file's permissions

}

//attempt to write basic content to the file

if (fwrite($create_file, "$png") === FALSE) {

echo "Error writing to file: ($file)\n";

}

fclose($create_file);

echo "File was created successfully!\n"; //tell the user that the file has been created successfully

exit; //exit the script

}else{ //the form hasn't been submitted!

header("Location: addfile.html"); //redirect the user back to the add file page

exit; //exit the script

}



?> 

 

Finally the png.txt file has:

 

<?php
header('Content-type: image/png');
$watermark = imagecreatefrompng("./images/watermarknds.png");
$template = imagecreatefrompng("./images/temp.png");
$aurl = '$file_contentactionshot';
$burl = '$file_contentboxshot';
$actionshot = imagecreatefromjpeg("$aurl");
$boxshot = imagecreatefromjpeg("$burl");
$textcolor = imagecolorallocate($template, 0, 0, 255);
$font = './fonts/bitdust2.ttf';
$watermark_width = imagesx($watermark);  
$watermark_height = imagesy($watermark);
$ip = $_SERVER['REMOTE_ADDR'];
$country = file_get_contents("api.hdfgdfgostip.info/get_html.php?ip=$ip");
list($widtha, $heighta) = getimagesize("$aurl");
list($widthb, $heightb) = getimagesize("$burl");
imagettftext($template, 9, 0, 6, 12, $textcolor, $font, "$country");
imagettftext($template, 9, 0, 6, 37, $textcolor, $font, "Your Ip: $ip");
imagettftext($template, 9, 0, 323, 293, $textcolor, $font, "Number:
$file_contentnumber
Full name:
$file_contentnamea
$file_contentnameb
Region:
$file_contentregion
Languages:
$file_contentlang
Genre:
$file_contentgenre");
imagecopyresampled($template, $actionshot, 85, 65, 0, 0, 200, 346, $widtha, $heighta);
imagecopyresampled($template, $boxshot, 320, 30, 0, 0, 185, 157, $widthb, $heightb);
imagecopymerge($template, $watermark, 111, 223, 0, 0, $watermark_width, $watermark_height, 30);
imagecopymerge($ndstemplate, $watermark, 347, 150, 0, 0, $watermark_width, $watermark_height, 30);
imagepng($template);
imagedestroy($watermark);
imagedestroy($template);
imagedestroy($actionshot);
imagedestroy($boxshot);
?>

 

Well basically what i want to do is using the html interface to input certain tdata and have the php code create the txt file with the inputted data.

Now there are certain variables like:

$file_name

$file_contentnumber

which will be inputted from the html interface.

 

Next i want to load the text file png.txt which has its own set of php codes but I want the variables in the png.txt which correspond with the html inputted data to change to what is inputted.

 

eg

$file_contentnumber : will be inputed by the user then loading png.txt change the $file_contentnumber in it to the inputed data.

 

In the end it will create a txt file with what all the code that is in png.txt with the variables that can be changed according to addfile.php and addfile.html, changed to what the user inputted.

 

I tried using file_get_contents function to load the png.txt file but the variables in it doesn't change to what is inputed.

 

Thanks a million for any help and sorry if i was a bit repetitive cause I'm a sorta a noob to php.

If you need more explianation please reply.

 

Thanks again

Link to comment
Share on other sites

yeah I do what it to be php code, they are already variables which i want to be subbed but dunno the correct phph function to do so like.

 

 

$file_contentactionshot

$file_contentboxshot

$file_contentnumber

$file_contentnamea

$file_contentnameb

$file_contentregion

$file_contentlang

$file_contentgenre

 

which will be submiited throught the form but do not change when the new file is wriitten with the contents of png.txt and the variables in it.

Link to comment
Share on other sites

You can only edit a post for a few minutes afterward.  It's to prevent problems where someone replies to your post, then you edit the content of that post, and everyone gets confused :)

 

About the problem - I believe the best solution is to make your png.txt like a template, and use special markers for the variables you want to substitute.  For example:

 

# The template
$var = %VAR%;
print $var;

 

# The template processor
$template = file_get_contents('template.txt');
$template = str_replace('%VAR%', "$var", $template);

 

And so on for each substitution you want to make.

 

There are more sophisticated template systems such as Smarty, but I think this will be good enough for what you need.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.