0

I have image upload script which shows this (Strict standards: Only variables should be passed by reference in C:\wamp\www\Fcomail-Final\cpanel\fcomail\Gallery.php on line 33 Call Stack) error Line no 33 is

require('../conn/include.php');
require('quick.php');
$query="SELECT * FROM category";
$result=mysql_query($query);
$project=$_POST['project'];
$alttext=$_POST['alttext'];
$relation=$_POST['Section'];;

if(isset($_FILES['image'])) {
    $errors=array();
    $allowed_ext=array('jpg','png','jpeg','JPG');
    $filename=$_FILES['image']['name'];
    $name=stripslashes($filename);
    **Line 33** $type=strtolower(end(explode('.',$filename)));
    $size=$_FILES['image']['size'];
    $file_tmp=$_FILES['image']['tmp_name'];
if(in_array($type,$allowed_ext) ===false) {
    $errors[]= "<span class=\"notification n-error\">Extenstion Not Allowed</span>";
}if($size > 1048576) {
    $errors[]= "<span class=\"notification n-error\">File must be less then 2mb</span>";
}if(file_exists('../../images/fcomail/gallery/'.$filename)) {
   $errors[]= "<span class=\"notification n-error\">File $filname Already Exists in directory</span>";
}if(empty($errors)) {
    if(move_uploaded_file($file_tmp, '../../images/fcomail/gallery/'.$filename)) {
        $insert="Insert into `my`.gallery(name,alttext,project,relation)VALUES('$name','$alttext','$project','$relation')";
        //echo $insert;
        $que=mysql_query($insert);
    echo "<span class=\"notification n-success\">File $filname Uploaded Sucessfully</span>";
    }
}else {
    foreach($errors as $error) {
        echo $error,'<br/>';    
    }
}
}

1 Answers1

2

You need to break the below line

$type=strtolower(end(explode('.',$filename)));

to

$fname = explode('.',$filename);
$filename = end($fname);
$type=strtolower($filename);

Reason :

From the documentation of end() in PHP Manual.

The array. This array is passed by reference because it is modified by the function. This means you must pass it a real variable and not a function returning an array because only actual variables may be passed by reference.

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126