Answer the question
In order to leave comments, you need to log in
Saves broken jpg, news parsing script, what's wrong?
The script parses the news, downloads the image from the link, saves the broken file to the server, what's wrong? :
if($f_Link){
$c=file_get_contents($f_Link);
$fh=fopen($_SERVER['DOCUMENT_ROOT']."/scripts/news.txt","w");
fwrite($fh,$c);
fclose($fh);
preg_match("/b-material-head__title\">(.{1,})<\/h1>/", $c, $h1);
preg_match("/class=\"b-material-head__date-day\ ">(.{10})<\/span>/", $c, $date);
preg_match("/link rel=\"image_src\" href=\"(.*)\">/U", $c, $img); -save image
preg_match("/(\C*<\/article>)/U", $c, $text);
$id=mysql_insert_id($LinkID);
if($img[1 ]){
$ext= strrchr($img[1],
mysql_unbuffered_query("INSERT INTO Message5 (User_ID,Subdivision_ID,Sub_Class_ID,Priority,Checked,Created,parent_class_id,parent_mess_id,foto) VALUES(1,'19','19',20,1,NOW(),'2',' ".$message."','str".$ext.":image/jpeg:1');", $LinkID);
$id=mysql_insert_id($LinkID);
copy($img[1],$_SERVER['DOCUMENT_ROOT']."/sysfiles/45_".$id.$ext);
}
}
-- -- There
is
a mini-picture, only it is in the body of the news, but should be at the top in the headline.
The script used to work without problems, the layout on the Russian newspaper website was updated, I am correcting regular expressions and I can’t solve the problem with the image in any way. Maybe someone sees the error?
Answer the question
In order to leave comments, you need to log in
Goodnight.
The problem is in the line:
$img['1'] contains '//cdnimg.rg.ru/img/content/138/31/30/pr_t_650x433.jpg'.
Try doing this:
The file will copy without problems.
And do checks so that you can determine the error yourself.
Do the same as you do now:
if(!copy($img[1],$_SERVER['DOCUMENT_ROOT']."/sysfiles/45_".$id.$ext)){
echo 'error';
}
else{
echo 'success';
}
$fh=fopen($_SERVER['DOCUMENT_ROOT']."/scripts/news.txt","w");
fwrite($fh,$c);
fclose($fh);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question