Php从文件夹中获取图像

时间:2018-04-19 18:51:25

标签: php ajax angular4-forms

我有以下代码,它给出了localhost中所有图像的列表: -

awk -v OFS=',' -v date=1 -v time=2 -v url=8 -v total=15 -v failed=18 '
    NR == 1 { print "Date", "aId", "classId", "total ops", "failed ops" }
    NF == failed {
        aid = cid = ""
        n = split($url, arr, /\//)
        for (i = 4; i <= n; ++i) {
            if (arr[i] ~ /^aId=/)
                aid = arr[i]
            else if (arr[i] ~ /^classId=/)
                cid = arr[i]
            if (aid != "" && cid != "") {
                gsub(/[^0-9]+/, "", aid)
                gsub(/[^0-9]+/, "", cid)
                gsub(/[^0-9]+/, "", $total)
                print $date " " $time, aid, cid, $total, $failed
                next
            }
        }
    }' twr.log

我得到了正确的输出: -

<?php
$target_dir = "uploadToper/";
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
$dir = "http://".$_SERVER['SERVER_NAME']."/apimerit/";
$collection = array();
/*
$collection[] = array('title' => 'sdfsdf', 'artist' =>'dsfsdf');
$collection[] = array('title' => 'dsfsdfs', 'artist' =>'dswdf');
$collection[] = array('title' => 'ssdfsf', 'artist' =>'dwer');
$collection[] = array('title' => 'sdsdfsd', 'artist' =>'dewrwedf');*/
foreach(glob($target_dir . '*.*') as $filename){
// echo $dir. $filename;
$imageFileType = pathinfo($filename,PATHINFO_EXTENSION);
$filename = explode("/",$filename)[1];
$collection[] = array('fileName' =>  $filename, 'fullPath'=>$dir.$target_dir. $filename, 'icon'=>$imageFileType);
 }
echo json_encode($collection);

?>

但是当我将我的网络服务器上传到godady时,它会出现以下错误:

  

&#34;解析错误:语法错误,意外&#39; [&#39;在   G:\ PleskVhosts \ worldplanetesolutions.com \ merithub2.worldplanetesolutions.com \ apimerit \ getToperImagesapi.php   在第15行&#34;

如果我删除&#34; [1]&#34; from&#34; $ filename = explode(&#34; /&#34;,$ filename)[1];&#34; 它为我提供了一个这样的文件名数组: -

  

[{&#34;文件名&#34;:[&#34; uploadToper&#34;&#34; slide1.jpg&#34],&#34; FULLPATH&#34;:&#34; HTTP :/
  /merithub2.worldplanetesolutions.com/apimerit/uploadToper/Array","icon":"jpg"},{"fileName":[" uploadToper&#34;&#34; slide2.jpg&#34],&#34; FULLPATH&#34;:&#34; HTTP://merithub2.worldplanetesolutions.com/apimerit/uploadToper/Array",& #34;图标&#34;:&#34; JPG&#34;},{&#34;文件名&#34;:[&#34; uploadToper&#34;&#34; toper1_2016.jpg&#34], &#34; FULLPATH&#34;:&#34; HTTP://merithub2.worldplanetesolutions.com/apimerit/uploadToper/Array",&#34;图标&#34;:&#34; JPG&#34;} ,{&#34;文件名&#34 ;: [&#34; uploadToper&#34;&#34; toper3_2015.jpg&#34],&#34; FULLPATH&#34;:&#34; HTTP:// merithub2.worldplanetesolutions.com/apimerit/uploadToper/Array","icon":"jpg"},{"fileName":["uploadToper& #34;&#34; toper3_2017.jpg&#34],&#34; FULLPATH&#34;:&#34; HTTP://merithub2.worldplanetesolutions.com/apimerit/uploadToper/Array",&# 34;图标&#34;:&#34; JPG&#34;},{&#34;文件名&#34;:[&#34; uploadToper&#34;&#34; toper4_2017.jpg&#34],& #34; FULLPATH&#34;:&#34; HTTP:// merithub2 .worldplanetesolutions.com / apimerit / uploadToper /阵列&#34;&#34;图标&#34;:&#34; JPG&#34;}]

0 个答案:

没有答案