I tried to take it off this error I do not understand why it happens, because I am uploading the file correctly... Right now is uploading the files, it shows me the error Error Notice: Only variables should be passed by reference in...
Notice: Only variables should be passed by reference in D:\xampp\htdocs\reduce-image\upload.php on line 10 ** I am facing in upload.php code. It's showing this error:
**
```
**upload.php**
<pre>
<?php
$file_type_error = '';
if($_FILES['upload_images']['name']) {
$upload_dir = "uploads/";
if (($_FILES["upload_images"]["type"] == "image/gif") ||
($_FILES["upload_images"]["type"] == "image/jpeg") ||
($_FILES["upload_images"]["type"] == "image/png") ||
($_FILES["upload_images"]["type"] == "image/pjpeg")) {
$file_name = $_FILES["upload_images"]["name"];
$extension = end((explode(".", $file_name)));
$upload_file = $upload_dir.$file_name;
if(move_uploaded_file($_FILES['upload_images']['tmp_name'],$upload_file)){
$source_image = $upload_file;
$image_destination = $upload_dir."min-".$file_name;
$compress_images = compressImage($source_image, $image_destination);
}
} else {
$file_type_error = "Upload only jpg or gif or png file type";
}
}
// created compressed JPEG file from source file
function compressImage($source_image, $compress_image) {
$image_info = getimagesize($source_image);
if ($image_info['mime'] == 'image/jpeg') {
$source_image = imagecreatefromjpeg($source_image);
imagejpeg($source_image, $compress_image, 75);
} elseif ($image_info['mime'] == 'image/gif') {
$source_image = imagecreatefromgif($source_image);
imagegif($source_image, $compress_image, 75);
} elseif ($image_info['mime'] == 'image/png') {
$source_image = imagecreatefrompng($source_image);
imagepng($source_image, $compress_image, 6);
}
return $compress_image;
}
?>
</pre> ```
<pre>
<?php
include('header.php');
?>
<script type="text/javascript" src="scripts/jquery.form.js"></script>
<script type="text/javascript" src="scripts/upload.js"></script>
<link type="text/css" rel="stylesheet" href="style.css" />
<link type="text/css" rel="stylesheet" href="style.css" />
<div class="container">
<h2>Reduce or Compress Image Size While Uploading in PHP</h2>
<form method="post" name="upload_form" id="upload_form" enctype="multipart/form-data" action="upload.php">
<label>Choose Images to Upload</label>
<input type="file" name="upload_images" id="image_file">
<div class="file_uploading hidden">
<label> </label>
<img src="uploading.gif" alt="Uploading......"/>
</div>
</form>
<div id="uploaded_images_preview">
</div>
</div>
<?php include('footer.php');?>
</pre>`
**js.file**
<pre>
$(document).ready(function(){
$('#image_file').on('change',function(){
$('#upload_form').ajaxForm({
target:'#uploaded_images_preview',
beforeSubmit:function(e){
$('.file_uploading').show();
},
success:function(e){
$('.file_uploading').hide();
},
error:function(e){
}
}).submit();
});
});
</pre> ```