
|
View Full Version : grabing it the hard way
ti_nhatrang 05-16-2007, 06:59 AM Hi guys,
I have this intranet where when I upload photos to my server, it automatically creates a html for me, and within that html, it gives me the direct link to the photo... however, I just want export/print/keep the values of it... Here is what I have so far:
$dp = "http://localhost/photo.php";
if (!$dp)
{
echo("<P>Error: unable to load URL file into $dp. Process aborted.</P>");
exit();
} else {
$sp = file_get_contents($dp);
// highlight_string($sp);
$search = ereg("http://users.jaz2.localhost/(.*).jpg", $sp, $content);
$surl = $content[1];
$file = (basename ($surl));
print $file;
}
I have about 20 links, and when I print, it ONLY print out one filename: mountain
Is there anyway I can make it print out more than just 1 basename?
Also, the JAZ2 is a folder name, and sometimes it changes, right now, it's only printing out whatever from JAZ2, is there anyway I can make it print out other folder as well, and put that folder in a value format like: $folderid?
Any kind of help would definately be helpful and appreciated.
ti_nhatrang 05-17-2007, 04:42 PM I guess I'm asking the wrong question or something... Is what I'm asking eve possible?
How about, how do I loop that script above?
Ks Jeppe 05-17-2007, 06:00 PM first of all, i really dont get the [color="red"] stuff you've added in that, and second, could you please explain again what you want to do, cause i really cant seem to understand it :S And a bit more of the code might be nice as well, where does $content come from?
Burhan 05-17-2007, 06:39 PM You need to use preg_match_all() (http://php.net/preg_match_all) instead of ereg, then loop through the array of results.
ti_nhatrang 05-18-2007, 12:31 AM First, thank you all that have been trying to help me.
the [color="red"] is something I add in so I can show it off or make a bold statement for easier reading of what I'm trying to say.
I basically have an html output files with a bunch of links directly to photos/image files that I need to extract... therefore, I want to write a script that find a common line and export it out to a $exportlink value for me.
ti_nhatrang 05-18-2007, 04:12 AM You need to use preg_match_all() (http://php.net/preg_match_all) instead of ereg, then loop through the array of results.
I think this is perfect and is what I need to use. If I use ereg, it only gives me the last results on that page:
here is the actual html line that php can load up:
<a href="picture.php?lg=us&&player=1&pix_id=5825&album_id=301&file=http%3A%2F%2Fuser.st1.localhost%2F301%2F2-out-the-grass.jpg" onClick="count_file_download('154');" class="blue orange capitalize">view online<strong>1.96 MB</strong></a><span class="small">jpg</span>
I've been trying to do the preg_match_all and I'm getting no luck for it just to pull out and display: http%3A%2F%2Fuser.st1.localhost%2F301%2F2-out-the-grass.jpgas a value $example and so on, and I have about 12 of these links.
Please help and once again, thank you all for attempting to help.
Burhan 05-20-2007, 03:55 AM This might work |(?:.*?)file=(.*?)(?:.*?)|mi
ti_nhatrang 05-21-2007, 11:06 PM it doesn't work, just give me a blank page
Burhan 05-22-2007, 07:26 AM How are you using it?
ti_nhatrang 05-22-2007, 08:06 PM I'm using it:
preg_match_all ("|(?:.*?)file=(.*?)(?:.*?)|mi", $var, $matches);
Jatinder 05-22-2007, 11:52 PM I don't know how your code can work. The very first line should give a parse error:
$dp = "http://localhost/photo.php";
Change it to :
$dp = 'http://localhost/photo.php';
Jatinder 05-23-2007, 12:14 AM Oops, I didn't realize that you used the [color ="Red"] to highlight the code sections.
The following code should work:
<?php
$dp = "http://localhost/photo.php";
$sp = @file_get_contents($dp);
if ($sp === FALSE) {
echo("<P>Error: unable to read the URL $dp. Process aborted.</P>");
exit();
}
preg_match_all("(http://users.jaz2.localhost/(.*).jpg)", $sp, $content);
foreach($content[0] as $surl) {
echo basename($surl),'<br />';
}
?>
ti_nhatrang 05-23-2007, 01:41 AM Perfect!!!! Thank you so much! It's quick, and simple... I've seen codes that could take up 2 pages to do what you just did. Once again, I want to thank all of those that has been helping me.
ti_nhatrang 05-23-2007, 03:39 PM It's weird, I try to wget the results, which is fine, but the download takes a while and it seem like the php file restarted/reload itself... is there anyway we have it not do this?
What I do is that I wget for every result... is there anyway we can break/stop after the wget is done?
Burhan 05-24-2007, 01:53 AM Your reload/restart is php timing out. This is a server setting, which you can override by set_time_limit() (http://php.net/set-time-limit).
ti_nhatrang 05-24-2007, 02:18 AM max_execution_time 3000000 3000000
max_input_time 600000 600000
memory_limit 400M 400M
thats what my server specs is running at...
ti_nhatrang 05-30-2007, 01:42 AM can anybody tell me why with those configurations still timesout page?
Ks Jeppe 05-30-2007, 08:38 AM When i had timeout errors, i found that it was caused by the lack of output to the browser or shell which called the script... have it print a bit from time to time, and make sure you flush the cacher if you have something like ob running...
ti_nhatrang 06-20-2007, 04:49 AM After many readings and googling, still can't find the right way to do this... how can I have it print a big from time to time when the command to grab happens already? please tell me what to do...
ti_nhatrang 07-02-2007, 08:12 AM Oops, I didn't realize that you used the [color ="Red"] to highlight the code sections.
The following code should work:
<?php
$dp = "http://localhost/photo.php";
$sp = @file_get_contents($dp);
if ($sp === FALSE) {
echo("<P>Error: unable to read the URL $dp. Process aborted.</P>");
exit();
}
preg_match_all("(http://users.jaz2.localhost/(.*).jpg)", $sp, $content);
foreach($content[0] as $surl) {
echo basename($surl),'<br />';
}
?>
Is there anyway we can limit the results from showing all of it to say maybe 4?
Jatinder 07-03-2007, 02:59 AM A simple way would be to use the array_slice function.
<?php
$dp = "http://localhost/photo.php";
$sp = @file_get_contents($dp);
if ($sp === FALSE) {
echo("<P>Error: unable to read the URL $dp. Process aborted.</P>");
exit();
}
preg_match_all("(http://users.jaz2.localhost/(.*).jpg)", $sp, $content);
//Retrieve the first 4 elements only
$temp = array_slice($content[0], 0, 4);
foreach($temp as $surl) {
echo basename($surl),'<br />';
}
?>
|