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…
<?php
if(isset($_FILES['csv'])){
$errors= array();
$file_name = $_FILES['csv']['name'];
$file_size = $_FILES['csv']['size'];
$file_tmp = $_FILES['csv']['tmp_name'];
$file_type = $_FILES['csv']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['csv']['name'])));// error line
$expensions= array("csv");
if(in_array($file_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a csv file.";
}
if($file_size > 2097152) {
$errors[]='File size must be excately 2 MB';
}
if(empty($errors)==true) {
move_uploaded_file($file_tmp,"images/".$file_name);
echo "Success";
}else{
print_r($errors);
}
}
?>
<html>
<body>
<form action = "" method = "POST" enctype = "multipart/form-data">
<input type = "file" name = "csv" />// If I change this to name this code does not works,
<input type = "submit" value="Subir archivos"/>
</form>
</body>
</html>
Advertisement
Answer
When calling end(), you must pass an array as a variable and not the return value of a function. So in…
$file_ext=strtolower(end(explode('.',$_FILES['csv']['name'])));
you can assign the return of explode() to a variable and then call end()
$file_parts =explode('.',$_FILES['csv']['name']);
$file_ext=strtolower(end($file_parts));
If you look at the documentation for end(), it shows the paramter is array &$array, the & shows it’s passed by reference.