4Manuals

  • PDF Cloud HOME

如何在目录中存储抓取的图像? Download

    具有Iframe表单的HTML文件,使用框架外的按钮通过JQuery提交表单按钮 CSS在像素中设置多个颜色渐变? 创建一个没有固定布局的HTML表,设置最大宽度,并且行不换行但溢出:隐藏 碳日期差异方法在Laravel 5.7中给出了错误的日期差异 如何使用PHP将https错误状态设置为404,以便可以通过.htaccess文件处理? 通过dropzone laravel通过电子邮件发送多个图像 在ajax调用成功之后添加文本区域 IntersectionObserver观察视口中的document.body上边缘 通过键合并两个数组,并将值附加到另一个数组中 如何在网站上模拟JavaScript控制台?

从表单提交名称后,php代码检查目录是否存在,如果目录存在,则从该目录显示图像。但是,如果该目录不存在,则会创建一个新目录。这是问题所在-代码在爬网时工作得很好,但没有将图像存储在指定目录内。问题似乎出在file_put_contents($directory , $image);部分。下面是完整的代码:

<?php

$images = array();
$directory = 'images '.$_POST["name"];
if (file_exists($directory)) {

if ($handle = opendir($directory)) {

while (false !== ($file = readdir($handle))) {

if (preg_match("/\.png$/", $file)) $images[] = $file;

elseif (preg_match("/\.jpg$/", $file)) $images[] = $file;

elseif (preg_match("/\.jpeg$/", $file)) $images[] = $file;

elseif (preg_match("/\.gif$/", $file)) $images[] = $file;

}

shuffle($images);

closedir($handle);

}

?>

<div class="cycle-slideshow" >

<?php

for($i= 0; $i < 3; $i++) {

  foreach ( new DirectoryIterator($directory) as $item ) {            
        if ($item->isFile()) {
            $path = $directory . '/' . $item;   
            echo '<img src="' . $path . '" class="displayed" style="max-width:100%; max-height:460px; position: absolute;
  right: 0px;   top: 0; bottom: 0; margin: auto;   vertical-align: middle; display: inline-block; "

   />';  
        }
    }  

}

  }
else {

    include "simple_html_dom.php";
   $html = file_get_html( "https://www.bing.com/images/search?q=barrack%20obama&FORM=HDRSC2" );
    $images = $html->find('img');
    $image_count = 50; //Enter the amount of images to be shown
    $i = 0;
    foreach($images as $image){
        if($i == $image_count) break;
        $i++;

      mkdir($directory);
      file_put_contents($directory , $image);

    }
        }

?> 

我在做什么错? 任何帮助表示赞赏。谢谢。

1 个答案:

答案 0 :(得分:0)

检查目录是否具有写权限,是否要创建新目录,而不是使用写权限创建的目录,这样它将存储您的文件并帮助从目录中检索它。

因为您已经在使用mkdir(),而不是像这样尝试设置权限

mkdir("dirname", 0777);



Similar searches
    如何使用Flutter将PDF文件转换为图像? 如何在WordPress中将“%1 $ s”和“%2 $ s”转换为字符串 如何连接到postgreSQL? 如何在Angular 2中进行2个以上的独立/并行http请求 三种模型关联结果