Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Problem with plus symbol in DB / response header

Hi,

Update: my mistake, the problem is because the plus sign is fetched from the query string, not the db:

// in a blade file
data-url = "/item/mime={{$file->mime}}"

so I used rawurlencode():

// in a blade file
data-url="/item/mime={{rawurlencode($file->mime)}}"

And it works!

---- Original Question ---- I am saving the mime type in the DB, and I need to return it with a response from the controller. For example, the mime type is image/svg+xml, I can see the plus symbol in the db.

But when I do:

$mime = DB::table('table')->find(1)->mime;
return response('success')->header('Content-Type', $mime);

If I dd($mime), it shows image/svg xml instead of image/svg+xml (And also the response headers in the browser show the same)

I am not sure if my problem is how I save it in the DB and maybe I need to decode it first, or the problem is when I fetch it back. Because I do see the plus symbol in the DB (MySQL, MySQL Workbench)

Thanks

0 likes
3 replies
Snapey's avatar

but also /item/mime=anything is not a valid url and neither is /item/mime=image/svg+xml

1 like
Ligonsker's avatar

@Snapey my bad, I meant /item?mime=anything. And yes regarding the svg+xml in the URL - I added the rawurlencode() to change the symbols to valid URL strings. In this example it turns the plus into %20 and then it worked.

I wasn't sure whether I should use rawurlencode() or urlencode() but both seem to do that job in my case, but I will need to re-read what's the difference to avoid problems

Snapey's avatar

if you use the route helper, the url is automatically encoded. EG, suppose your route name is "item"

data-url = "{{ route('item', ['mime' => $file->mime]) }}"

Please or to participate in this conversation.