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>'; Link to comment https://forums.phpfreaks.com/topic/280100-white-space/ 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>'; Link to comment https://forums.phpfreaks.com/topic/280100-white-space/#findComment-1440474 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? Link to comment https://forums.phpfreaks.com/topic/280100-white-space/#findComment-1440475 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>'; Link to comment https://forums.phpfreaks.com/topic/280100-white-space/#findComment-1440479 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. Link to comment https://forums.phpfreaks.com/topic/280100-white-space/#findComment-1440480 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 Link to comment https://forums.phpfreaks.com/topic/280100-white-space/#findComment-1440481 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. Link to comment https://forums.phpfreaks.com/topic/280100-white-space/#findComment-1440485 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. Link to comment https://forums.phpfreaks.com/topic/280100-white-space/#findComment-1440500 Share on other sites More sharing options...
Doug Posted July 13, 2013 Author Share Posted July 13, 2013 Thanks all for the cometns. Especially for the code AbraCadaver. It works! Link to comment https://forums.phpfreaks.com/topic/280100-white-space/#findComment-1440593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.