I am trying to get the following function to retain the original file name on upload.
Right now it uploads the image and stores it in the correct folder; however, it changes the name of the file to image.png
.
PHP:
class Upload {
function upimg($file, $up = "./upload/") {
$whitelist = array("jpg", "jpeg", "png", "gif");
if (isset($_FILES[$file]) && $_FILES[$file]['error'] == 0) {
$info = pathinfo($_FILES[$file]['name']);
$extension = $info['extension'];
list($width, $height, $type, $attr) = getimagesize($_FILES[$file]['tmp_name']);
if (($width > 10 || $height > 10) & in_array($extension, $whitelist)) {
$url = $file . '.' . $extension;
move_uploaded_file($_FILES[$file]['tmp_name'], $up . $url);
return $url;
}
}
}
}
I imagine this is happening because $file
isn't actually holding the original file name...not sure how to resolve this. Where did i go wrong??