Jump to content

Query string decoding - I'm totally stuck


Willstedt

Recommended Posts

Hi

 

I am totally stuck with my image rescaling script and need help. The script is supposed to download images from the net, rescale them and save a local copy. The image url to be rescaled is sent to the script in a query string.

The problem is image links with special characters like å, æ ø, ä, ö and similar; I can't get them decoded correctly.

 

This basic script displays the essense of the problem:

 

image_scale.php?file=http://www.mpx.no/img/produktbilder/Olympus/Kamera%20tilbehør/E0413744.jpg

<?php
  $file = $_REQUEST["file"];
  $file = rawurldecode($file);
  $dst_img=ImageCreateTrueColor(80,80);
  $src_img=imagecreatefromjpeg($file);

  imagecopyresampled($dst_img,$src_img,0,0,0,0,80,80,80,80);
  Header("Content-type: image/jpeg");
  Imagejpeg($dst_img,'',60);
  imagedestroy($dst_img);
  imagedestroy($src_img);
?>

 

The strange thing is that the script works perfectly fine if I paste the url to the image directly into the code like this:

<?php
  $file = "http://www.mpx.no/img/produktbilder/Olympus/Kamera%20tilbehør/E0413744.jpg";
  $dst_img=ImageCreateTrueColor(80,80);
  $src_img=imagecreatefromjpeg($file);

  imagecopyresampled($dst_img,$src_img,0,0,0,0,80,80,80,80);
  Header("Content-type: image/jpeg");
  Imagejpeg($dst_img,'',60);
  imagedestroy($dst_img);
  imagedestroy($src_img);
?>

 

I have tried a ton of different UTF-8 encode/decode, Rawurl Encode/Decode and just have to admit to myself that I can't solve the problem.

Please help me - this is getting quite frustrating  :'(

 

Cheers

Anders

Link to comment
https://forums.phpfreaks.com/topic/67083-query-string-decoding-im-totally-stuck/
Share on other sites

I should probably mention the error message I get when trying to parse the posted query string:

Warning: imagecreatefromjpeg(http://www.mpx.no/img/produktbilder/Olympus/Kamera tilbehør/E0413744.jpg) [function.imagecreatefromjpeg]: failed to open stream: HTTP request failed! HTTP/1.1 400

 

The imagecreatefromjpeg function works fine if I set the same image link as a variable in the script.

 

Does anyone have a clue about the solution to the problem?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.