Doug Posted July 12, 2013 Share Posted July 12, 2013 I've been trying to solve this for the past 2 days! Please help.I get this message while trying to validate the code in W3c valifation service. bad value %20images/image_name%20 for attribute src on element img: Whitespace in path component. Use %20 in place of spaces.There is no white space in the lines below. OR is there? I have put %20 in all white spaces that I could find with no effect. if (is_file(MM_UPLOADPATH . $row['picture']) . filesize(MM_UPLOADPATH . $row['picture']) > 0){echo'%20<a href="pictures.php">%20<img src="%20' . MM_UPLOADPATH . $row['picture'] . '%20" alt="sevenoaks latest pic" style="width:75px; maxheight:110px; margin:5px; padding:5px;"></a>'; if (is_file(MM_UPLOADPATH . $row['picture']) . filesize(MM_UPLOADPATH . $row['picture']) > 0){echo'%20<a href="pictures.php">%20<img src="%20' . MM_UPLOADPATH . $row['picture'] . '%20" alt="sevenoaks latest pic" style="width:75px; maxheight:110px; margin:5px; padding:5px;"></a>'; Quote Link to comment Share on other sites More sharing options...
.josh Posted July 12, 2013 Share Posted July 12, 2013 why are you even surrounding the src value with whitespace at all? Is your path/to/file really " path/to/file " vs. "path/to/file" ? Did you try just doing if (is_file(MM_UPLOADPATH . $row['picture']) . filesize(MM_UPLOADPATH . $row['picture']) > 0){echo'%20<a href="pictures.php">%20<img src="' . MM_UPLOADPATH . $row['picture'] . '" alt="sevenoaks latest pic" style="width:75px; maxheight:110px; margin:5px; padding:5px;"></a>'; Quote Link to comment Share on other sites More sharing options...
Doug Posted July 12, 2013 Author Share Posted July 12, 2013 Yes, I did! It's wjat I started out with. No difference sadly. I get the error message 6 times but there are ten images being displayed. Why would that be? Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 12, 2013 Share Posted July 12, 2013 Try building this var and then using in the src: $src = urlencode(MM_UPLOADPATH . $row['picture']); echo '<a href="pictures.php"><img src="' . $src . '" alt="sevenoaks latest pic" style="width:75px; maxheight:110px; margin:5px; padding:5px;"></a>'; Quote Link to comment Share on other sites More sharing options...
.josh Posted July 12, 2013 Share Posted July 12, 2013 yah that was my next guess... $row['picture'] (the file name) has spaces in it for some of them. Quote Link to comment Share on other sites More sharing options...
Doug Posted July 12, 2013 Author Share Posted July 12, 2013 thnaks...that got rid of the errors., sadly it also got rid of the images on the page! www.onesevenoaks.co.uk Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 12, 2013 Share Posted July 12, 2013 $src = str_replace(' ', '%20', MM_UPLOADPATH . $row['picture']); My bad, I wasn't thinking. Probably other characters that we don't want to encode. Quote Link to comment Share on other sites More sharing options...
DavidAM Posted July 12, 2013 Share Posted July 12, 2013 urlencode will encode the directory separators (slashes) in MM_UPLOADPATH (and in $row['picture'] if it has any subdirectories). You have to encode each component of the path individually and then piece it back together. Or use the shortcut from AbraCadaver if you are sure you will never have any other special characters. If you know MM_UPLOADPATH is clean, and $row['picture'] will not have subdirectories, you can just encode $row['picture'] before concatenation. Quote Link to comment Share on other sites More sharing options...
Solution Doug Posted July 13, 2013 Author Solution Share Posted July 13, 2013 Thanks all for the cometns. Especially for the code AbraCadaver. It works! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.