vishalkoradiya / timthumb

Automatically exported from code.google.com/p/timthumb
0 stars 0 forks source link

Problem with relative path on windows = temprary fix #356

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Install timthumb.php
2.open browser and load this address 
http://localhost/timthumb.php?src=myimage.jpg
3.You get an error "Could not find the internal image you specified."

What is the expected output?
Showing the image.

What do you see instead?
The error shown above.

What version of the product are you using? On what operating system?
v. 2.8.10 / OS Win7 64-bit
Separate installations of Apache / PHP 5.3.9

Please provide any additional information below.
The problem I tracked down was on lines 877 - 881
Line 877: if (strstr($_SERVER['SCRIPT_FILENAME'],':')) {
The result on this line you'll get /timthumb.php
And then on line 884 where the foreach loop starts for $base you'll get
$base = C:/timthumb.php/myimage.jpg
Nice, a?

The temp fix
Add these lines right after the foreach llop starts
if (strrpos($sub,'.')) {
$sub = substr($sub, 0, strrpos($sub,'/'));
}

Explanation:
if (strrpos($sub,'.')) { - On this line the code will look inf there es a dot. 
If there is a dot it didn't strip the filename from the string.
$sub = substr($sub, 0, strrpos($sub,'/')); - this line will strip the filename 
along with the last occurence of slah /
And after that the code will continue to work.

I know it's an ugly solution, but for a temp fix it'll work.

I am also open for another solutions.

Thank you and Regards,
Ivan

Original issue reported on code.google.com by batz...@gmail.com on 14 Mar 2012 at 9:34