I want to upload images using PHP, with proper validation such as to check width and to replace white spaces with - or _ in filename.
Here is my code:
function ubimg($fileName, $fileType, $fileTmpName, $pathToSaveIn) {
$flagUpload = false;
$rndFileName = "";
$rndNum = rand(10000000, 9899999999);
if (($fileType == "image/gif") || ($fileType == "image/jpeg") || ($fileType == "image/png") && imagesx < 600) {
$nameFile = $rndNum . "_" . $fileName;
$cfile = preg_replace('/\s\s+/', "_", $nameFile);
$_SESSION['bimg'] = $cfile;
if (!file_exists($pathToSaveIn . "/" . $nameFile)) {
move_uploaded_file($fileTmpName, $pathToSaveIn . "/" . $nameFile);
$flagUpload = true;
}
}
else {
msgbox("error", $php_errormsg);
}
return $flagUpload; //may be return true or false
}
I have used preg_replace
but its not working on removing spaces from file name???? any solution