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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.