I have been receiving this notice and I don't understand why or how to fix it?
Notice: Undefined index: in /website/classes/Validate.php on line 56 Warning: exif_imagetype(): Filename cannot be empty in /website/classes/Validate.php on line 56
This is what I am doing to get this notice.
$validate = new Validate();
if($validate->fileCheck('file')){
echo "success";
}else{
echo "failed";
}
That is where I thought I am sending the file name to the class which I then use in the class like this.
public function fileCheck($name){
$allowed = array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF);
$file = exif_imagetype($_FILES[$name]['tmp_name']);
if(in_array($file, $allowed)){
return true;
}
return false;
}
If anyone could help me understand why it is throwing this Notice and how to solve it I would very much appreciate it.
Related
After updating our server to PHP 5.4 and a Drupal site to Drupal 6.37 I keep getting this error message and I am not able to get past it
Fatal error: Call to undefined function drupal_get_path() in /home/mysite/public_html/includes/module.inc on line 285
this is the related function call
function module_load_include($type, $module, $name = NULL) {
if (empty($name)) {
$name = $module;
}
$file = './'. drupal_get_path('module', $module) ."/$name.$type";
if (is_file($file)) {
require_once $file;
}
else {
return FALSE;
}
}
Even when I try to run update.php I still get the same error
I am new to Drupal so any help will be greatly appreciated
Please let me know what additional info you may need since it is my first post here and as I said I don't know much about Drupal
I am building a pdf conversion utility for my user.
I am working in CakePhp and my controller is receiving Ajax call.
Why i am getting Notice:8 error
Controller:
public function convertToPdf() {
$this->autoRender = false;
$pdf = new WkHtmlToPdf;
//$this->RequestHandler->respondAs('json');
// echo $convertData = json_encode($inputVal);
if ($this->RequestHandler->isAjax()) {
$pdfName = uniqid();
if ($_FILES['conversionSourceFile']) {
echo "File";
$pdf->addPage($_FILES['conversionSourceFile']['tmp_name']);
} elseif ($_POST['conversionSourceUrl']) {
echo "Url";
$pdf->addPage($_POST['conversionSourceUrl']);
} elseif ($_POST['conversionSourceHtml']) {
echo "Html";
$pdf->addPage('<html>' . $_POST['conversionSourceHtml'] . '</html>');
}
$saveToPath = 'upload/' . $pdfName . '.pdf';
if ($pdf->saveAs($saveToPath)) {
echo 'upload/' . $pdfName . '.pdf';
}
}
}
Error:
Notice (8): Undefined index: conversionSourceFile [APP/Controller/PdfsController.php, line 42]
Code Context
if ($this->RequestHandler->isAjax()) {
$pdfName = uniqid();
if ($_FILES['conversionSourceFile']) {
PdfsController::convertToPdf() - APP/Controller/PdfsController.php, line 42
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE/Cake/Controller/Controller.php, line 486
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 187
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 162
[main] - APP/webroot/index.php, line 109
To avoid notice in your code you have to use isset() OR !empty().
Using isset() and !empty() you can check whether variable is set and does not have an empty value.
e.g,
if (isset($_FILES['conversionSourceFile'])) {
// your code
}
OR
if (!empty($_FILES['conversionSourceFile'])) {
// your code
}
Simply check to isset $_FILES superglobal variable to prevent notice when not set.
if (isset($_FILES['conversionSourceFile'])) {
// Do more stuff
}
You need to check the first condition, with an "isset" or "!empty ()", like:
if(isset($_FILES['conversionSourceFile'])){...}
I solved the error "Notice (8): Undefined index" changing the order var $ uses.
before:
class GastosController extends AppController {
var $uses = array('Comprobante','Gasto','TipoGasto');
...
...
..
After:
class GastosController extends AppController {
var $uses = array('Gasto','Comprobante','TipoGasto');
..
..
..
Put the name that corresponds to the class (Gasto) first.
I am currently working on Yii. I want to check that if some value is exists into database then echo something otherwise save into database.
I am doing:
$model = Users::model()->findByAttributes(array('googleid'=>$google_id));
if($model)
{
echo "Good";
}
else
{
echo $model->googleid = $google_id;
$model->save();
}
But when I am running this code then I am getting error :
Fatal error: Call to undefined method stdClass::save() in E:\wamp\www\customers\protected\views\users\googlelogin.php on line 76
What may be the reason for this error, I am unable to figure out, please help me
Thanks in advance
I got the solution, I was making a mistake that $model was returning a NULL value and I was insterting the value in that model, the following solution made my work :
$model = Users::model()->findByAttributes(array('googleid'=>$google_id));
if($model)
{
echo "Good";
}
else
{
$model_new = new Users;
echo $model_new->googleid = $google_id;
$model_new->save();
}
Thanks for the responses
I've written the following piece of code:
Class stackOverflowExample {
private $hash;
private $cookie_file;
public function __construct(){
#session_start();
if(isset($_SESSION['gc_hash'])){
$this->$hash = $_SESSION['gc_hash'];
}else{
$this->$hash = md5(time());
$_SESSION['gc_hash'] = $this->$hash;
}
$this->$cookie_file = "./cookies/{$this->$hash}.txt";
}
}
But I'm getting this error
Notice: Undefined variable: hash in
/var/www/gausie/gc/GeoCaching.Class.php on line 21
Fatal error: Cannot access empty property in
/var/www/gausie/gc/GeoCaching.Class.php on line 21
In the original code, line 21 refers to $this->$hash = $_SESSION['gc_hash'];.
I can't see why this is happening, although I'm new to OO PHP. Any ideas?
just replace $this->$hash by $this->hash
$this->$hash means variable with name equals to variable $hash value
I am getting the following error in the following code:
Class primeField implements field {
private $intmodulus = '';
public function generator(){
return ;
}
public function modulus(){
return $this->$intmodulus;
}
public function __construct($modulus , $base=0) {
if (is_resource($modulus) && get_resource_type($modulus) == "GMP integer"){
$this->$intmodulus = $modulus;
} else{
$this->$intmodulus = gmp_init($modulus , $base); \\line 70
}
}
}
$a = new primeField(11);
$a->modulus();
Notice: Undefined variable: intmodulus in /Users/admin/PHP ECC/finitefield.php on line 70
Fatal error: Cannot access empty property in /Users/admin/PHP ECC/finitefield.php on line 70
Why
The syntax is
$this->intmodulus
not $this->$intmodulus.
You get an error saying "cannot access empty property" because $intmodulus is undefined and hence accessing it gives NULL. The NULL gets converted into an empty string when you attempt to use it as a property name.
If the value of $intmodulus was the name of a valid property (e.g. if $intmodulus == "intmodulus"), you would be accessing the property with that name.
$this->$intmodulus should be $this->intmodulus
See the PHP documentation for Variable variables for info on what is happening.