Forum Moderators: coopster
the code is:
<img width="240" height="180" src="01%20-%20Raptor%20AMD%20Sempron_image001.jpg">
I want to change the 01%20-%20Raptor%20AMD%20Sempron_image001.jpg becouse the location of the file will be changed after the upload.
the location for instains will be /images/uploaded/01%20-%20Raptor%20AMD%20Sempron_image001.jpg.
After the upload i have the image at the right location and i can access it trough the browser.
How can replace that string so that it will be at the right location in the HTML file?
I tryed a few preg_replace options, but i doesn't changes it. I think this is becouse of the urlencoded string.
Does someone has en example?
The filename i get trough the $_FILE variable.
Thx in advance.
I Upload 2 files.
1. The HTML file (01 - Raptor AMD Sempron.html).
2. The image that belongs the the HTML file (01 - Raptor AMD Sempron_image001.jpg).
so i get 2 files.
And i need/want to replace the image file to an standard location like '/images'.
When i want to view that HTML file, i won't see the image becouse the location is diffrent.
The image filename within the HTML file is urlencoded.
Wat i need is some way to change the location/filename within that HTML file. I have the original file and i can urlencode it. But when i try a preg_replace with it, it doesn't change anything. Not even when I do it manualy.
Could it be that for some reason the %20 hex values are a problem?
Can you, or someone else give me an small example about how i can change the location or something?
Thx in advance.
when the files are uploaded you are saving them somewhere, when you save them use the original filename and fire it through str_replace to swap the spaces
also you really shouldn't use spaces in filenames or directory names.
I don't care about spaces or stuff like that, and i know it is better to not use it. But hey.. its not that i don't want to :(.
The problem is.. that in the HTML file there is an <img> tag.. in where the src="" attribute with value is. Now i need to change that value. Becouse that points to the image file that has been uploaded.
My prob is.. i can change stuff in the HTML file with preg_replace etc..
But for some reason i can't change that src="(.*?)".
So for example.
i need to change:
<img width="240" height="180" src="01%20-%20Raptor%20AMD%20Sempron_image001.jpg">
In to:
<img width="240" height="180" src="/images/01%20-%20Raptor%20AMD%20Sempron_image001.jpg">
But what i try i can't get it working.
That is my problem.
Grab the html file into a string with file_get_contents() then do the replacement.
<?php
$str = file_get_contents($html_file);
$str = str_replace($img_name, '/images/'.$img_name, $str);
?>