Invalid characters


#1

When i try to upload an image i get this error on apache logs

The given path is misformatted or contained invalid characters: Cannot map GET /carbac/public/category_image/%7B%22car_images%22:[%7B%22file%22:%22C://Users//rmumo//AppData//Local//Temp//php965B.tmp%22%7D]%7D HTTP/1.1 to file,

my code for uploading the image. What am i doing wrong with my uploadfile variable, kindly assist

public function add(Request $request, Response $response, $args){

$car_category_id = $request->getParam(‘car_category_id’);
$name = $request->getParam(‘name’);
$description = $request->getParam(‘description’);
$price = $request->getParam(‘price’);
$mileage = $request->getParam(‘mileage’);
$fuel_type = $request->getParam(‘fuel_type’);
$transmission = $request->getParam(‘transmission’);
$fuel_economy = $request->getParam(‘fuel_economy’);
$air_condition = $request->getParam(‘air_condition’);
$hourly_price = $request->getParam(‘hourly_price’);
$daily_price = $request->getParam(‘daily_price’);
$year = $request->getParam(‘year’);

//Upload directory for profile image
$directory = DIR . ‘/…/…/…/public/category_image’;

$uploadedFiles = @$request->getUploadedFiles()[‘category_image’];

$avater = array();

if(is_array($uploadedFiles) | is_object($uploadedFiles)) {

foreach ($uploadedFiles as $uploadedFile) {

if ($uploadedFile->getError() === UPLOAD_ERR_OK) {
$avater[] = \App\Helpers\FileUpload::moveUploadedFile($directory, $uploadedFile, [‘png’, ‘jpeg’, ‘gif’, ‘jpg’]);
mkdir(’./category_image’);
} else {

(new Flash)->addMessage(‘message’, “Sorry, something went wrong from our end, please notify site owner”);

return $response->withRedirect($this->router->pathFor(‘users’));
}
}

}

if( ! $avater ) {

(new Flash)->addMessage(‘message’, “Sorry, Please make image you are uploading is either a ‘png’, ‘jpeg’, ‘gif’ or ‘jpg’”);

return $response->withRedirect($this->router->pathFor(‘car_description’));
}

$car_description = CarDescription::create([
‘car_category_id’ => $car_category_id,
‘name’ => $name,
‘description’ => $description,
‘year’ => $year,
‘mileage’ => $mileage,
‘price’ => $price,
‘fuel_type’ => $fuel_type,
‘transmission’ => $transmission,
‘fuel_economy’ => $fuel_economy,
‘air_condition’ => $air_condition,
‘hourly_price’ => $hourly_price,
‘daily_price’ => $daily_price,
‘images’ => json_encode($avater)
]);

Any help will be appreciated.


#2

You appear to be confusing file system paths (C:\Users\...) and virtual paths within the URL (that often map to file system paths but are not the same and can never include details like a drive letter). I may be wrong but you aren’t generating the URL in the code you’ve shared.

I could also spot a | bitwise operator where you probably wanted a || boolean one.