473,394 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

finding the full path of an image ?

I want to list all images from a url.

here is my code snippet which finds an image from a url:

$url = "http://asdf.com/";

$text = @implode("", file($url));

while (eregi("[:space:]*(src)[:space:]*=[:space:]*([^ >]+)", $text , $regs))
{
echo $regs[2];
$text = substr($text, strpos($text, $regs[1]) + strlen($regs[1]));
}

the only problem is that I would like to have it full path but sometimes I
get stuff like:

"../images/test.jpg"

how can I get all images with full path ?
Jul 17 '05 #1
1 1676
Yang wrote:
while (eregi("[:space:]*(src)[:space:]*=[:space:]*([^ >]+)", $text ,
$regs)) {
echo $regs[2];
$text = substr($text, strpos($text, $regs[1]) + strlen($regs[1]));
}

This will also catch links like:

<script src='foo.js' />
the only problem is that I would like to have it full path but
sometimes I get stuff like:

"../images/test.jpg"

how can I get all images with full path ?


What you could do, is prepend the host and the path and apply preg_replace
in a while loop to replace "dirname/.." sections as follows:

$url = "http://www.example.com/somedir/../images/test.jpg";

while (strstr($url, "/../")) {
$url = preg_replace("|/[^/]+/\.\./|", "/", $url);
}

However, there are more rules to consider. Per example, links like
"//images.example.com/images/whatever.gif". In this case, you should only
preprend "http:" to make the link valid.

The following file gives you an idea:

http://playground.jwscripts.com/imagegrab.phps
JW

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Don | last post by:
How do I retrieve the full path (C:\.....filename) of a file uploaded to a php script on the server. I think $_FILES will only provide 'name', which is only the filename itself. Thanks, Don ...
4
by: Hal Vaughan | last post by:
I want to have a config file for my program, which means I need to know where the config file is. If I type: java myclass and it runs myclass.class, is there any way to obtain the location of...
11
by: Fuzzyman | last post by:
What's the best, cross platform, way of finding out the directory a script is run from ? I've googled a bit, but can't get a clear answer. On sys.argv the docs say : argv is the script name...
3
by: Bill Brother | last post by:
Is it possible to retrieve the local full path of an image ( not the url )?
2
by: Nathan Sokalski | last post by:
I have a rollover script that I plan to use for many of my pages. When I preload the images, the directories must be relevant to the location of the HTML file that uses the script, which will not...
4
by: m | last post by:
Hello I need to find out full URL of my application name, I tried using Request.ServerVariables but it returns only serverername, and I need virtual directory name as well. Thnx in advance
5
by: Jay | last post by:
Hello, I am writing a c++ program that stores some values in a config located in it's directory. is there a way in c++ to get the full path of the running program so I can open the file not...
1
by: Rico | last post by:
Hello, I have an ole object field (Access XP/2002) which I store images in. I have a couple of questions regarding this; is it possible to determine the image dimensions? Secondly, is there...
2
by: =?Utf-8?B?U2hhbQ==?= | last post by:
Hai, I am developing application which handles to create thumbnail form a video file. I am successfully created image and i displayed it into browser by, bit.Save(Response.OutputStream,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.