I am using phpexcel library with zend framwork.
I want to send mail to user with excel file attachment, all are working good but mail send with two attachment one is duplicate, i dont know why.
here is my function which is used to export excel and send it to user
public function exportandmail($name = NULL) {
if ($name === NULL) {
$name = 'excel_' . date('Y_m_d');
}
$name = $name.'.xlsx';
$objWriter = PHPExcel_IOFactory::createWriter($this->_excel, 'Excel2007');
$objWriter->save("public/uploads/Mailexcel/".$name);
$message="<table width='90%' align='center' >
<tr>
<th height='15' style='background-color:#037296;padding:10px;color:#FFFFFF' align='left'>excel</th>
</tr>
<tr>
<td style='padding:10px'><strong>Please find the attachment. </strong>
</td>
<tr>
<td style='padding:10px'>
Thanks,
</td>
</tr>
</table>";
$mail = new Zend_Mail();
$mail->setBodyHtml($message);
$mail->setFrom('sender#gmail.com', 'sender');
$mail->addTo('user#gmail.com');
$mail->setSubject('find attachment');
$fileContents = file_get_contents("public/uploads/Mailexcel/".$name);
$file = $mail->createAttachment($fileContents);
$file->filename = "excel.xlsx";
$mail->addAttachment($file);
$mail->send();
exit;
}
Thanks in advance.
I got the solution,
In my code, i use both createAttachment and addAttachment, thats why my mail send with duplicate attachment.
Remove addAttachment and its working fine.
$fileContents = file_get_contents("public/uploads/Mailexcel/".$name);
$file = $mail->createAttachment($fileContents);
$file->filename = "excel.xlsx";
$mail->addAttachment($file); // Remove this
$mail->send();
Related
Following the guide here
http://documentation.concrete5.org/developers/express/using-the-express-entry-block-to-output-entry-data
I am able to create the same results but if I change the example and attempt to use the attribute of an express object which is a file link or a date field the view block returns the following error
"Object of class DoctrineProxies__CG__\Concrete\Core\Entity\File\File could not be converted to string"
Can the below code be modified to resolve this or is this a core issue?
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<?php
if (isset($entry) && is_object($entry)) {
$drawings = $entry->getDrawings();
?>
<table id="datatable", class="table">
<thead>
<tr>
<th>Drawing Name</th>
<th>Drawing Number</th>
<th>Revision</th>
<th>Revision Date</th>
<th>Category</th>
<th>PDF</th>
</tr>
</thead>
<tbody>
<?php if (count($drawings)) {
foreach($drawings as $drawing) { ?>
<tr>
<td><?=$drawing->getDrawingName()?></td>
<td><?=$drawing->getDrawingNumber()?></td>
<td><?=$drawing->getRevision()?></td>
<td><?=$drawing->getDrawingRevisionDate()?></td>
<td><?=$drawing->getDrawingCategory()?></td>
<td><?=$drawing->getDrawingPdf()?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td colspan="6">No drawings found.</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
the problem comes from this line:
<?=$drawing->getDrawingPdf()?>
what getDrawingPdf() is returning is a file object so it cannot be output to the screen like a simple string. First, you would have to extract a string from it. For instance, the following code would extract the file name and show it.
<?php
$drawingPdf = $drawing->getDrawingPdf();
$pdfFileName = is_object($drawingPdf)? $drawingPdf->getFileName() : '';
?>
<td><?=$pdfFileName?></td>
What this code does is first get the file object which you already had in your code.
Then if we have a proper file object, get the file name. If it's not a proper file object (you never now it might have been deleted) we return and empty string.
And finally, we output our string $pdfFileName (which is either the filename or an empty string) in your table.
Hope this helps
I am making user meta fields. I have to implement a field named business_profile and implement editor on it. I have implemented the editor but I can't seem to either save its value or retrieve it. Below is my code.
<tr>
<th>
<label for="address">Business Profile</label></th>
<td><?php
$content = get_the_author_meta('business_profile', $user->ID);
$editor_id = 'mycustomeditor';
wp_editor($content, $editor_id);
?>
</td>
</tr>
And for update:
update_usermeta($user_id, 'business_profile', $_POST['business_profile']);
Where am I wrong?
Your code should read
update_usermeta($user_id, 'business_profile', $_POST['mycustomeditor']);
since mycustomeditor is the $editor_id than this is how the $_POST variable would be named .
business_profile on the other hand is just the meta_data for user or user_meta name .
It appears you just confused the two .
Currently, my site has a table in a database that contain user name and password. The front end has 2 textboxes and a login button. Once the user fills out those two fields and click login, it will check if user name and password is matched in the database, if so, let them in and set session variable to check through out the entier site. Is this secure enough? How do i convert this to form authentication? I don't want to throw out my login table. Can i still use it if i was to convert this to form authentication? Can anyone point me or show me how this could be done? Thanks
The standard login I use is somethig like this:
index.html:
<form action="login.php" method="post">
<table width="100%" border="0" style = "border-top: 2px solid #CCC; padding-top: 15px;">
<tr>
<td><input type="text" class="text_box" placeholder="Usuario" name="user" id="user"></td>
</tr>
<tr>
<td><input type="password" class="text_box" placeholder="ContraseƱa" name="pass" id="pass"></td>
</tr>
<tr>
<td>
<?php
show_message();
?>
<input type="submit" value="Ingresar" class="boton_submit">
</td>
</tr>
</table>
</form>
And the php...
<?php
if(isset($_POST["user"]) && isset($_POST["pass"])){
include('conect_to_database.php');
$user = $_POST["user"];
$pass = $_POST["pass"];
if(!filter_var($_POST["user"], FILTER_VALIDATE_EMAIL)) {
//Not a valid email ... sends back to login form
header( 'Location: index.php' ) ;
exit();
}
$query = "SELECT id FROM user where user = ? and pass = ? LIMIT 1";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("ss", $user, $pass);
$stmt->execute();
$stmt->bind_result($id);
while ($stmt->fetch()) {
//set your session variable
header( 'Location: ../../control_panel.php' ) ;
exit();
}
//echo invalid user... sends back to login form
header( 'Location: index.php' ) ;
}
?>
I would also recommend checking for special chars in both user and password.
Also, you should never store passwords in your database. You should just store a hash of the real password using special algorithms.
i working on plugin that has in back-end to add url of of site or post and short description and in front end show then in a widget,i have button for small image of post to be uploaded but it didi't work out but same code work fine in normal php...
$upload_errors = array(
// http://www.php.net/manual/en/features.file-upload.errors.php
UPLOAD_ERR_OK => "No errors.",
UPLOAD_ERR_INI_SIZE => "Larger than upload_max_filesize.",
UPLOAD_ERR_FORM_SIZE => "Larger than form MAX_FILE_SIZE.",
UPLOAD_ERR_PARTIAL => "Partial upload.",
UPLOAD_ERR_NO_FILE => "No file.",
UPLOAD_ERR_NO_TMP_DIR => "No temporary directory.",
UPLOAD_ERR_CANT_WRITE => "Can't write to disk.",
UPLOAD_ERR_EXTENSION => "File upload stopped by extension."
);
// process the form data
$tmp_file = $_FILES['file_upload']['tmp_name'];
$target_file = basename($_FILES['file_upload']['name']);
$upload_dir = "uploads";
// You will probably want to first use file_exists() to make sure
// there isn't already a file by the same name.
// move_uploaded_file will return false if $tmp_file is not a valid upload file
// or if it cannot be moved for any other reason
if(move_uploaded_file($tmp_file, $upload_dir."/".$target_file)) {
$message = "File uploaded successfully.";
} else {
$error = $_FILES['file_upload']['error'];
$message = $upload_errors[$error];
}
this is the form used to upload image
<form action='' method='post' name="text_form" onsubmit="return Blank_TextField_Validator()" enctype="multipart/form-data">
<table class='form-table'><tr valign='top'>
<th scope='row'><lable for='new_Directory_name'>Enter the Title:</lable></th>
<td><input type='text' id='newtextchange' name='newtextchange' size="100" /></br></td>
</tr>
<tr>
<th scope='row'><lable for='new_Directory_name'>Enter the Description:</lable></th>
<td><textarea rows="4" cols="50" name='textarea1'>
</textarea></br></td>
</tr>
<tr>
<th scope='row'><lable for='new_Directory_name'>Enter the URL:</lable></th>
<td><input type='text' id='newtextchange1' name='newtextchange1' size="100" /></br></td>
</tr>
<tr>
<th scope='row'><lable for='new_Directory_name'>Upload image:</lable></th>
<td> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /><input type="file" name="file_upload" /><br><br><input id='addtobow' class='button-secondary action' type='submit' value='Add to Best of web' name='submit'/></td>
</tr>
</table>
</form>
You should look at wp_handle_upload for this one.
The example given there is very usefull.
To save the url you can use the following lines:
$upload_overrides = array( 'test_form' => false );
$source = wp_handle_upload( $_FILES['file'], $upload_overrides );
if ( $source )
$input = serialize( $source );
Hope it helps!
problem is with the file upload url and this is how i fix it..,now it is working fine...
$tmp_file = $_FILES['file_upload']['tmp_name'];
$target_file = basename($_FILES['file_upload']['name']);
//$upload_dir = "D:\softwares_installed\wamp\www\wordpress\wp-content\plugins\bestofweb\uploads";
$upload_dir =ABSPATH . "wp-content/plugins/bestofweb/uploads";
$up_urlp1="/wp-content/plugins/bestofweb/uploads";
// You will probably want to first use file_exists() to make sure
// there isn't already a file by the same name.
// move_uploaded_file will return false if $tmp_file is not a valid upload file
// or if it cannot be moved for any other reason
if(move_uploaded_file($tmp_file, $upload_dir."/".$target_file)) {
//$message = "File uploaded successfully.";
//echo $upload_dir."/".$target_file;
//echo bloginfo('wpurl');
$up_url= $up_urlp1."/".$target_file;
//echo $up_url;
//if($message == "File uploaded successfully.")
// {
// $imgpath=$upload_dir.
// }
} else {
$error = $_FILES['file_upload']['error'];
// $message = $upload_errors[$error];
}
It doesn't display ite1 value in the pdf. Why? Could you please, correct my mistake?
<?php
set_include_path($_SERVER['DOCUMENT_ROOT'] .'/mpdf/');
require('mpdf.php');
$n = 0;
$mpdf=new mPDF();
require_once('../../includes/common.php');
$result = mysql_query("SELECT * from sgc where year = '2010'") or die(mysql_error());
$row=mysql_fetch_array($result);
$nric=$row['nric'];
$row=mysql_fetch_array($result);
$meta_ite=$row['meta_ite'];
$mpdf->WriteHTML('<p>Hello World</p>');
$html1 = '<table>
<tr>
<td width="388">Module Description</td>
<td width="111"><div align="center">Grade</div></td>
<td width="92"><div align="center">Earned</div></td>
<td width="96"><div align="center">Authority</div></td>
<td width="74"><div align="center">Series</div></td>
</tr>';
$unser = $meta_ite;
$unser = unserialize($unser);
$count = count($unser);
for($j=0;$j<$count;$j++)
{
$ite1 = $unser[$i][0];
//print_r ($unser[$i][0]."--".$unser[$i][1]."--".$unser[$i][2]);
$html1 .= '<tr><td width="388">'.$nric.'</td>
<td width="111">'.$count.'</td>
<td width="92"><div align="center">'.$ite1.'</div></td>
<td width="96">ITE</td>
<td width="74">2010</td>
</tr>';
}
$html1 .= '</table>';
$mpdf->WriteHTML($html1);
$mpdf->Output('filename.pdf','D');
?>
first you include your mpdf file
require_once('./mpdf/mpdf.php');
also open debug functionality to see the error.
$mpdf->debug = true;
Note: ensure that you have complete permission (777 or 755) for the following folders on server:
/ttfontdata/
/tmp/
/graph_cache/