New to PHP simple code, but cant get it to work
Posted: Wed Jun 11, 2008 6:22 am
Hi, im new to php and have made a simple code to generate HTML files using a form and a php script. My problem is that the script goes through without any errors but when I check the directory the file hasnt been generated. I am sure it has permission to write as I had it generating files, problems came when I put in the html code to write, any help would be much appreciated, thanks.
My code is as follows.
<?php
/* If file_put_contents doesn't exists, let's make our own */
if( !function_exists('file_put_contents') ) {
function file_put_contents($file_name, $file_contents) {
/* Open the file */
if( !$handle = fopen($file_name, 'w') ) {
trigger_error("Cannot open file ($file_name)", E_USER_ERROR);
return false;
}
/* Write to it */
if( fwrite($handle, $file_contents) === FALSE ) {
trigger_error("Cannot write to file ($file_name)", E_USER_ERROR);
return false;
}
/* Close it */
fclose($handle);
return true;
}
}
$filename = $_POST["filename"];
$title = $_POST["title"];
$location = $_POST["location"];
$salary = $_POST["salary"];
$company = $_POST["company"];
$role = $_POST["role"];
$person = $_POST["person"];
$ref = $_POST["ref"];
$consultant = $_POST["consultant"];
$html = "
<html>
<head>
<title>$title</Title>
</Head>
<body>
<table border='1' bordercolor='#747474' cellpadding='0' cellspacing='0' align='center'>
<tr>
<td>
<Table width='700' border='0' style='font-family:arial;font-size:80%;'><form enctype='multipart/form-data' method='post' action='application.php'>
<tr>
<td width='600' align='center'>
<img src='../images/spechead.gif'>
</td>
<td width='*' valign='top' align='right' rowspan='5'>
<img src='../images/rightcorner.gif' width='100'>
</td>
</tr>
<tr>
<td align='center' style='font-family:arial;font-size:200%;'>
<b>$title</b>
</td>
</tr>
<tr>
<td align='center' valign='top'>
$location
</td>
</tr>
<tr>
<td align='center' valign='top'>
$salary
</td>
</tr>
</table>
<table width='700' border='0' style='font-family:arial;font-size:80%;'>
<tr>
<td colspan='2'>
<b>The Company - Our Client:</b><br>
$company
<Br><br>
<b>The Role - Main Duties and Responsibilities:</b><br>
$role
<br><br>
<b>The Person - Skills, Knowledge, Qualifications and Experience</b><br>
$person
<br><br>
<b>Company Fusion:</b><br>
Building on 20 years market experience, Company Fusion specializes in providing flexible solutions through permanent and contract assignments, managed services and a variety of integrated, service innovations. Our mission is to be the leading UK Recruitment ‘Firm’ of choice for employees, jobseekers and employers. As a result we are committed to delivering the highest quality recruitment services in the marketplace.
<br><br>
<b>Personal Representation – Apply Today ”if you don’t ask, you don’t get”:</b><br>
If you would like to discuss this or any of our vacancies in confidence please email a copy of your CV with contact details to: <a href='mailto:recruitment@comapnyfusion.com'>recruitment@companyfusion.com</a> and/or call 0845 270 1266 for an informal discussion.
<br><br>
<b>Referrals Scheme £100 - £250:</b><br>
Do you know someone who is suitable for this role? Do you know of a company recruiting? E-mail a copy of their CV with the reference number or company contact numbers/email and your details clearly stating <b>REFERRAL</b> in the subject to: <a href='mailto:recruitment@companyfusion.com'>recruitment@companyfusion.com</a> and you could receive between <b>£100 - £250</b> Gift Voucher of your choice!
</td>
</tr>
<tr>
<td colspan='2'>
</td>
</tr>
<tr>
<td colspan='2'>
<b>To apply for this position please complete the form bellow:</b>
</td>
</tr>
<tr>
<td>Name:</td>
<td><input type='text' name='cand_name'></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type='text' name='cand_phone'></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type='text' name='cand_email'></td>
</tr>
<tr>
<td>Your CV:</td>
<td><input type='file' name='filename' /> <a href='../cvbuild.html' target='new'>Build a CV</a></td>
</tr>
<tr>
<td colspan='2'> </td>
</tr>
<tr>
<td colspan='2'>Help us to help you and tell us why you would be good for this position.</td>
</tr>
<tr>
<td> </td>
<td><textarea cols='50' rows='10' name='comments'></textarea></td>
</tr>
<tr>
<td colspan='2'>
</td>
</tr>
<tr>
<td colspan='2' align='center'><input type='submit' value='Apply For Role'><INPUT type='hidden' name='recipient' VALUE='recruitment@companyfusion.com, $consultant'><INPUT type='hidden' name='refrence' VALUE='$ref'></td>
</tr>
</table></form>
</td>
</tr>
</table>
</body>
</html>";
file_put_contents('jobspecs/$filename', $html);
?>
Its my impression this should preety much instantly write the file into the specified folder. the html doc comes out at about 3kb
My code is as follows.
<?php
/* If file_put_contents doesn't exists, let's make our own */
if( !function_exists('file_put_contents') ) {
function file_put_contents($file_name, $file_contents) {
/* Open the file */
if( !$handle = fopen($file_name, 'w') ) {
trigger_error("Cannot open file ($file_name)", E_USER_ERROR);
return false;
}
/* Write to it */
if( fwrite($handle, $file_contents) === FALSE ) {
trigger_error("Cannot write to file ($file_name)", E_USER_ERROR);
return false;
}
/* Close it */
fclose($handle);
return true;
}
}
$filename = $_POST["filename"];
$title = $_POST["title"];
$location = $_POST["location"];
$salary = $_POST["salary"];
$company = $_POST["company"];
$role = $_POST["role"];
$person = $_POST["person"];
$ref = $_POST["ref"];
$consultant = $_POST["consultant"];
$html = "
<html>
<head>
<title>$title</Title>
</Head>
<body>
<table border='1' bordercolor='#747474' cellpadding='0' cellspacing='0' align='center'>
<tr>
<td>
<Table width='700' border='0' style='font-family:arial;font-size:80%;'><form enctype='multipart/form-data' method='post' action='application.php'>
<tr>
<td width='600' align='center'>
<img src='../images/spechead.gif'>
</td>
<td width='*' valign='top' align='right' rowspan='5'>
<img src='../images/rightcorner.gif' width='100'>
</td>
</tr>
<tr>
<td align='center' style='font-family:arial;font-size:200%;'>
<b>$title</b>
</td>
</tr>
<tr>
<td align='center' valign='top'>
$location
</td>
</tr>
<tr>
<td align='center' valign='top'>
$salary
</td>
</tr>
</table>
<table width='700' border='0' style='font-family:arial;font-size:80%;'>
<tr>
<td colspan='2'>
<b>The Company - Our Client:</b><br>
$company
<Br><br>
<b>The Role - Main Duties and Responsibilities:</b><br>
$role
<br><br>
<b>The Person - Skills, Knowledge, Qualifications and Experience</b><br>
$person
<br><br>
<b>Company Fusion:</b><br>
Building on 20 years market experience, Company Fusion specializes in providing flexible solutions through permanent and contract assignments, managed services and a variety of integrated, service innovations. Our mission is to be the leading UK Recruitment ‘Firm’ of choice for employees, jobseekers and employers. As a result we are committed to delivering the highest quality recruitment services in the marketplace.
<br><br>
<b>Personal Representation – Apply Today ”if you don’t ask, you don’t get”:</b><br>
If you would like to discuss this or any of our vacancies in confidence please email a copy of your CV with contact details to: <a href='mailto:recruitment@comapnyfusion.com'>recruitment@companyfusion.com</a> and/or call 0845 270 1266 for an informal discussion.
<br><br>
<b>Referrals Scheme £100 - £250:</b><br>
Do you know someone who is suitable for this role? Do you know of a company recruiting? E-mail a copy of their CV with the reference number or company contact numbers/email and your details clearly stating <b>REFERRAL</b> in the subject to: <a href='mailto:recruitment@companyfusion.com'>recruitment@companyfusion.com</a> and you could receive between <b>£100 - £250</b> Gift Voucher of your choice!
</td>
</tr>
<tr>
<td colspan='2'>
</td>
</tr>
<tr>
<td colspan='2'>
<b>To apply for this position please complete the form bellow:</b>
</td>
</tr>
<tr>
<td>Name:</td>
<td><input type='text' name='cand_name'></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type='text' name='cand_phone'></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type='text' name='cand_email'></td>
</tr>
<tr>
<td>Your CV:</td>
<td><input type='file' name='filename' /> <a href='../cvbuild.html' target='new'>Build a CV</a></td>
</tr>
<tr>
<td colspan='2'> </td>
</tr>
<tr>
<td colspan='2'>Help us to help you and tell us why you would be good for this position.</td>
</tr>
<tr>
<td> </td>
<td><textarea cols='50' rows='10' name='comments'></textarea></td>
</tr>
<tr>
<td colspan='2'>
</td>
</tr>
<tr>
<td colspan='2' align='center'><input type='submit' value='Apply For Role'><INPUT type='hidden' name='recipient' VALUE='recruitment@companyfusion.com, $consultant'><INPUT type='hidden' name='refrence' VALUE='$ref'></td>
</tr>
</table></form>
</td>
</tr>
</table>
</body>
</html>";
file_put_contents('jobspecs/$filename', $html);
?>
Its my impression this should preety much instantly write the file into the specified folder. the html doc comes out at about 3kb