yii phpexcel file reader no response - yii

I have a piece of code that is
$excelFile = '/tmp/sheet.xls' ;
Yii::import('application.vendors.PHPExcel',true);
$inputFileType = PHPExcel_IOFactory::identify($excelFile);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($excelFile);
$objWorkSheet = $objPHPExcel->getActiveSheet();
$highestRow = $objWorkSheet->getHighestRow();
$hightestColumn = $objWorkSheet->getHightestColumn();
$hightestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
echo '<table>'."\n" ;
for($row=2; $row<$highestRow ; ++$row){
echo '<tr>'."\n" ;
for($col=0; $col < $highestColumnIndex ; ++$col){
echo '<td>'.$objWorksheet->getCellByColumnAndRow($col,$row)->getValue().'</td>'."\n";
}
echo '</tr>'."\n" ;
}
echo '</table>'."\n" ;
But when this code execute I do not get any file display. I also tried to put debugs to check where it failed, I could localize the error to getActiveSheet.
Any help would be appreciated
Thanks

Try import PHPExcel like this:
spl_autoload_unregister(array('YiiBase', 'autoload'));
Yii::import('application.vendors.PHPExcel', true);
$this->objPHPExcel = new PHPExcel();
spl_autoload_register(array('YiiBase', 'autoload'));

Here is how i display the imported excel file and works:
spl_autoload_unregister(array('YiiBase','autoload'));
Yii::import("application.vendors.phpexcel.Classes.PHPExcel", true);
$inputFileType = PHPExcel_IOFactory::identify($path);
$objReader = PHPExcel_IOFactory::createReader($inputFileType); //Excel5);
$objPHPExcel = $objReader->load($path);
spl_autoload_register(array('YiiBase','autoload'));
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
foreach ($worksheet->getRowIterator() as $row) {
$rowIndex=$row->getRowIndex();
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set
foreach ($cellIterator as $cellIndex=>$cell) {
if (!is_null($cell)) {
if($rowIndex >1 && $cellIndex<=55){
$cellVal=$cell->getCalculatedValue();
echo $cellVal;
}
}
}
}
}

Related

I can't access admin panel of my script : Invalid query You have an error in your SQL syntax

I have an error message when i try to access my script (php):
Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's marketing advertising'' at line 1
This is a admin php file contain mysql query
<?php
$stt_query = $ocdb->get_rows("SELECT * FROM ".$config->prefix."search order by id desc limit 13" );
if (count( $stt_query ) > 0) {
foreach ($stt_query as $row) :
?>
<li><?php echo $row['title'];?></li>
<?php
endforeach;
}
?>
the php query page:
<?php class OCDB { var $server = ""; var $port = ""; var $db = ""; var $user = ""; var $password = ""; var $prefix = ""; var $insert_id; var $link; function __construct($_server, $_port, $_db, $_user, $_password, $_prefix) { $this->server = $_server; $this->port = $_port; $this->db = $_db; $this->user = $_user; $this->password = $_password; $this->prefix = $_prefix; $host = $this->server; if (defined('DB_HOST_PORT') && !empty($this->port)) $host .= ':'.$this->port; $this->link = mysqli_connect($host, $this->user, $this->password) or die("Could not connect: " . mysqli_connect_error()); mysqli_select_db($this->link, $this->db) or die ('Can not use database : ' . mysqli_error($this->link)); mysqli_query($this->link, 'SET NAMES utf8'); } function get_row($_sql) { //$res = $this->link->query($_sql); //if ($this->link->error) { //try { //throw new Exception("MySQL error $mysqli->error <br> Query:<br> $query", $this->link->errno); //} catch(Exception $e ) { //echo "Error No: ".$e->getCode(). " - ". $e->getMessage() . "<br >"; //echo nl2br($e->getTraceAsString()); //} //} $result = mysqli_query($this->link, $_sql) or die("Invalid query: " . mysqli_error($this->link)); $row = mysqli_fetch_array($result, MYSQL_ASSOC); mysqli_free_result($result); return $row; mysqli_close($this->link); } function get_rows($_sql) { $rows = array(); $result = mysqli_query($this->link, $_sql) or die("Invalid query: " . mysqli_error($this->link)); while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) { $rows[] = $row; } mysqli_free_result($result); return $rows; } function get_var($_sql) { $result = mysqli_query($this->link, $_sql) or die("Invalid query: " . mysqli_error($this->link)); $row = mysqli_fetch_array($result, MYSQL_NUM); mysqli_free_result($result); if ($row && is_array($row)) return $row[0]; return false; } function query($_sql) { $result = mysqli_query($this->link, $_sql) or die("Invalid query: " . mysqli_error($this->link)); $this->insert_id = mysqli_insert_id($this->link); return $result; } function escape_string($_string) { return mysqli_real_escape_string($this->link, $_string); } } ?>
Please can you help me i can't access admin panel because of this error.
Thanks

How can I bind correctly my variables to my tokens?

I can't figure out what causes this error, I'm burned out already. I can't figure out how to solve this.
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter
number: number of bound variables does not match number of tokens in C:\wamp64\www\myproject-dev\public\viajes\orden_mantenimiento\controller.php on line 77
This happens when I try to execute my create method so heres the whole method:
if ($type == 'create') {
$Records = $request->models;
foreach ($Records as $rec) {
if (isset($request->pky)) {
$fky = $request->fky;
$rec->$fky = $request->pky;
}
$aError = Validate($rec);
$statement = $conn->prepare('INSERT INTO order (id, idVehiculo, idTipo, fecha, kilometraje, horaIn, horaSal, proyecto, jefeProy, aprobadoPor, descripcion)
VALUES (:id, :idVehiculo, idTipo, :fecha, :kilometraje, :horaIn, :horaSal, :proyecto, :jefeProy, :aprobadoPor, descripcion)');
$statement->bindValue(':id', $rec->id);
$statement->bindValue(':idVehiculo', $rec->idVehiculo);
$statement->bindValue(':idTipo', $rec->idTipo);
$statement->bindValue(':fecha', $rec->fecha);
$statement->bindValue(':kilometraje', $rec->kilometraje);
$statement->bindvalue(':horaIn', $rec->horaIn);
$statement->bindvalue(':horaSal', $rec->horaSal);
$statement->bindValue(':proyecto', $rec->proyecto);
$statement->bindValue(':jefeProy', $rec->jefeProy);
$statement->bindValue(':aprobadoPor', $rec->aprobadoPor);
$statement->bindValue(':descripcion', $rec->descripcion);
if (!$statement->execute()) { // **========================== THIS IS LINE 77 ===================**
$aErrInfo = $statement->errorInfo();
$aError = array();
$aError[] = array('success' => false);
$aError[] = array('msg' => $aErrInfo[1]);
$aError[] = array('error' => $aErrInfo[2]);
$respuesta["errors"] = $aError;
echo "statement error".$respuesta;
} else {
$rec->id = $conn->lastInsertId();
$respuesta["data"] = $rec;
echo "Data bound.";
}
} else {
$respuesta["errors"] = $aError;
echo "ERROR";
}
}
}
Thanks a lot in advance.

what does mean for this error "Notice: Array to string conversion in line 96"

this is the example of signup page. the error is"Notice: Array to string conversion in
C:\xampp\htdocs\sample\signup.php on line 96" what are the possible solutions.
here is the code........
<?php
$con = mysqli_connect('localhost','root') or die(mysqli_error());
mysqli_select_db($con,'kms') or die (mysqli_error());
if (isset($_POST['techno']) && isset($_FILES['profile_picture']))
{
$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$password = $_POST['password'];
$psw_repeat = $_POST['psw_repeat'];
$dob = $_POST['dob'];
$gender = $_POST['gender'];
$occupation = $_POST['occupation'];
$address = $_POST['address'];
$about = $_POST['about'];
$phonenumber = $_POST['phonenumber'];
$profile_picture = $_FILES['profile_picture'];
$q = "INSERT INTO user (firstname,middlename,lastname,email,password,dob,gender,occupation,address,about,phonenumber,profile_picture) values ('$firstname','$middlename','$lastname','$email','$password',$dob,'$gender','$occupation','$address','$about',$phonenumber,'$profile_picture')";
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["profile_picture"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["profile_picture"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["profile_picture"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["profile_picture"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["profile_picture"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
if($psw_repeat != $password)
{
echo("Password does not match");
}
mysqli_query($con,$q) or die(mysqli_error($con));
mysqli_close($con);
}
?>
in line number 96...the code is for inserting data into database...
i have googled this error....ut there is no solution

timthumb not working after site migration

I just move my site from xfactorapp.com and any new uploaded picture has no thumbnail. Image is on server but thumbnail is not generated.
How can i change that code to make thumbnail visible from new server?
function href_t`imthumb($file, $set = null, $xf = true) {
if (!$set || !$xf) {
$timthumb = webpath_assets('/timthumb.php');
$href = $timthumb . '?src=' . $file;
if (xcount($set) > 0) {
foreach ($set as $k => $v) {
$href .= '&' . $k . '=' . $v;
}
}
return $href;
} else {
$param['w'] = 150;
$param['h'] = 150;
$param['zc'] = 0;
$param['q'] = 90;
if (DEV) {
$app = DEV_PREFIX . APP_VERSION;
} else {
$app = LIVE_PREFIX . APP_VERSION;
}
if (xcount($set) > 0) {
foreach ($set as $k => $v) {
$param[$k] = $v;
}
$file = '/' . $app . $file;
$protocol = 'http';
if (isSSL()) {
$protocol = 'https';
}
return $protocol . '://thumb.xfactorapp.com/tt/' . implode('/', $param) . $file;
}
}
}
wich give me:
<img class="img-responsive" alt="building" src="http://thumb.xfactorapp.com/tt/263/147/2/90/v3/uploads/_lifttec/cms/58529051881f8f0d87ab1401/5947fffeac28b_200-ATJ-Platforma-autoridicatoare-articulata.jpg">
i wish to change code to take thumbnail with parnam properties but from upload not from thumb.xfactorapp.com
Thanks
Just change $xf from true to false $xf = false.
If you changed server, May be GD Library is missing,So Install and Restart Apache then check your file permission.
// To install GD Library
sudo apt-get install php5.6-gd
// To Restart Apache2
sudo /etc/init.d/apache2 restart

How to assign data to excel sheets in alphabetical order in PHPExcel

I am trying to create excel generated file. I want to get usernames from database and then print names according to each letter in alphabet. I am able to create sheets in alphabetical order but cant print names on each sheet.
Here is what i have so far:
<?php
require_once ('PHPExcel/Classes/PHPExcel.php');
include('inc/database_connection.php');
$conn = mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME);
$conn->set_charset('utf8_unicode_ci');//if not by default
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
$F = $objPHPExcel->getActiveSheet();
$Letter='B';
$Number=2;
for($i=321; $i<347; $i++)
{
$F = $objPHPExcel->createSheet($i); //Setting index when creating
$F->setCellValue('A1', "Username")
->setCellValue('B1', "Project")
->setCellValue('C1', "Processes");
$request="SELECT username FROM user WHERE username LIKE '".chr($i+32)."%'";
$result= $conn->query($request);//get the result (ressource)
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
$username=$row["username"];
$F->setCellValue('A'.$Number, ' '.$username.' ');
$F->getRowDimension('1')->setRowHeight(20);
$F->getColumnDimension($Letter)->setWidth(30);
++$Number;
}
} else
{
echo "0 results";
}
$F->setTitle(chr($i));
}
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="HeadCount.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
?>
Is there way to print usernames for each spreedsheet? Thank you.
Problem was solved by removing if statement
$objPHPExcel = new PHPExcel();
$F = $objPHPExcel->getActiveSheet();
for($i=321; $i<347; $i++)
{
$Letter='B';
$Number=2;
$F = $objPHPExcel->createSheet($i); //Setting index when creating
$objPHPExcel->setActiveSheetIndex(1);
$F->setCellValue('A1', "Username")
->setCellValue('B1', "Project")
->setCellValue('C1', "Processes");
$request="SELECT username FROM user WHERE username LIKE '".chr($i+32)."%'";
$result= $conn->query($request);//get the result (ressource)
// output data of each row
while($row = $result->fetch_assoc())
{
$username=$row["username"];
$F->setCellValue('A'.$Number, ' '.$username.' ');
$F->getRowDimension('1')->setRowHeight(20);
$F->getColumnDimension($Letter)->setWidth(30);
++$Number;
}
$F->setTitle(chr($i));
}