inspireddesign Posted June 2, 2009 Share Posted June 2, 2009 Hello all. I have a function that inserts an image into an RTF Word document using various control words (below). My problem is that when the image is inserted I get both the image and the path at which the image is located. So when I open the output document I see ../path/imagename.jpg and the image below. Is there a way to trim the path from the image that is being inputted? Thanks for any help on this one. <?php function add_image($image, $ratio, $align = 'left') { $file = @file_get_contents($image); if (empty($file)) return NULL; $image .= "\\ql "; $image .= "{"; $image .= "\\pict\\jpegblip\\picscalex". $ratio ."\\picscaley". $ratio ."\\bliptag132000428 "; $image .= trim(bin2hex($file)); $image .= "\n}\n"; $image .= "\\par\n"; return $image; } ?> Link to comment https://forums.phpfreaks.com/topic/160660-trimming/ Share on other sites More sharing options...
thebadbad Posted June 2, 2009 Share Posted June 2, 2009 basename(): <?php function add_image($image, $ratio, $align = 'left') { $file = @file_get_contents($image); if (empty($file)) return NULL; $image = basename($image); $image .= "\\ql "; $image .= "{"; $image .= "\\pict\\jpegblip\\picscalex". $ratio ."\\picscaley". $ratio ."\\bliptag132000428 "; $image .= trim(bin2hex($file)); $image .= "\n}\n"; $image .= "\\par\n"; return $image; } ?> Link to comment https://forums.phpfreaks.com/topic/160660-trimming/#findComment-847879 Share on other sites More sharing options...
inspireddesign Posted June 2, 2009 Author Share Posted June 2, 2009 Well... we are on the right path ... it removed the path but still producing the image name. Any thoughts? Link to comment https://forums.phpfreaks.com/topic/160660-trimming/#findComment-847884 Share on other sites More sharing options...
inspireddesign Posted June 2, 2009 Author Share Posted June 2, 2009 Quote Well... we are on the right path ... it removed the path but still producing the image name. Any thoughts? Would like to remove the filename as well as the path. Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/160660-trimming/#findComment-847904 Share on other sites More sharing options...
inspireddesign Posted June 2, 2009 Author Share Posted June 2, 2009 Is there anyway to trim both the path and the filename from the output. Currently, the below solution trims the path but still leaves the filename with extension. Learning a whole lot from this forum. Thanks for everyone's help <?php function add_image($image, $ratio, $align = 'left') { $file = @file_get_contents($image); if (empty($file)) return NULL; $image = basename($image); $image .= "\\ql "; $image .= "{"; $image .= "\\pict\\jpegblip\\picscalex". $ratio ."\\picscaley". $ratio ."\\bliptag132000428 "; $image .= trim(bin2hex($file)); $image .= "\n}\n"; $image .= "\\par\n"; return $image; } ?> Link to comment https://forums.phpfreaks.com/topic/160660-trimming/#findComment-847983 Share on other sites More sharing options...
thebadbad Posted June 2, 2009 Share Posted June 2, 2009 Oh, you want to remove the whole lot? Then in your original code, start the $image string with "\\ql " instead of concatenating it with the path ('cause $image contains the path to start with): <?php function add_image($image, $ratio, $align = 'left') { $file = @file_get_contents($image); if (empty($file)) return NULL; $image = "\\ql "; $image .= "{"; $image .= "\\pict\\jpegblip\\picscalex". $ratio ."\\picscaley". $ratio ."\\bliptag132000428 "; $image .= trim(bin2hex($file)); $image .= "\n}\n"; $image .= "\\par\n"; return $image; } ?> Link to comment https://forums.phpfreaks.com/topic/160660-trimming/#findComment-847997 Share on other sites More sharing options...
inspireddesign Posted June 2, 2009 Author Share Posted June 2, 2009 Thanks! That worked! Link to comment https://forums.phpfreaks.com/topic/160660-trimming/#findComment-848007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.