so i have a script that uses opendir(). It is accessing files on a network drive. I get this following error:
[Warning: opendir(/displayads/): failed to open dir: No such file or directory in /home/ebrad/public_html/tools/tools/displayads_prep.php on line 36
Warning: opendir(/displayads/jpgs): failed to open dir: No such file or directory in /home/ebrad/public_html/tools/tools/displayads_prep.php on line 49]
here is my code rather lengthy -sorry:
[#!/usr/bin/php
<?php
#ob_start();
@mkdir($_ENV['HOME'] . '/displayads');
@mkdir($_ENV['HOME'] . '/displayads/jpgs/');
function stripext($filename) {
return preg_replace('/\.(jpg|eps|pdf)$/i', '', $filename);
}
function getext($filename) {
preg_match('/\.([^\.]+)$/i', $filename, $matches);
return $matches[1];
}
function getnewrawads () {
echo date('[Y-m-d H:i:s] ') . "BEGIN Grabbing ads from admaster1.\n";
$cmd = "rsync -tv --delete username@server:/cygdrive/d/Vol1/filename/* {$_ENV['HOME']}/displayads/";
echo "$cmd\n";
passthru($cmd);
echo date('[Y-m-d H:i:s] ') . "DONE Grabbing ads from admaster1.\n";
echo date('[Y-m-d H:i:s] ') . "BEGIN Grabbing ads from amp (SharedFiles).\n";
$cmd = "rsync -tv --delete \"username@server:/Volumes/File\\ Share/Shares/SharedFiles/Class\\ Graphics/EPS\\ Ads/*\" {$_ENV['HOME']}/displayads/";
echo "$cmd\n";
passthru($cmd);
echo date('[Y-m-d H:i:s] ') . "DONE Grabbing ads from amp (SharedFiles).\n";
}
function getrawads () {
$rawads = array();
if ($dh = opendir($_ENV['HOME'] . '/displayads/')) {
while (false !== ($file = readdir($dh))) {
if (preg_match('/\.(pdf|eps)$/i', $file) > 0) {
$rawads[$_ENV['HOME'] . '/displayads/' . $file] = stripext($file);
}
}
closedir($dh);
}
return $rawads;
}
function getjpegads_helper($dir, &$jpegads) {
$dirs = array();
if ($dh = opendir($dir)) {
while (false !== ($file = readdir($dh))) {
if ($file == "." || $file == "..") { continue; }
$fullpath = $dir . '/' . $file;
if (filesize($fullpath) <= 10240) {
@unlink($fullpath);
continue;
}
if (preg_match('/\.jpg$/i', $file) > 0) {
$jpegads[$fullpath] = stripext($file);
}
if (is_dir($fullpath)) {
$dirs[] = $fullpath;
}
}
closedir($dh);
foreach ($dirs as $dir) {
getjpegads_helper($dir, $jpegads);
}
}
return $jpegads;
}
function getjpegads() {
$jpegads = array();
return getjpegads_helper ($_ENV['HOME'] . '/displayads/jpgs', $jpegads);
}
function getunjpegedadlist () {
$rawads = getrawads();
$jpegads = getjpegads();
return array_keys(array_diff($rawads, $jpegads));
}
function prepads () {
echo getnewrawads();
$ads = getunjpegedadlist();
$jpgdir = $_ENV['HOME'] . '/displayads/jpgs/' . date('Ymd');
@mkdir($jpgdir);
$cmdbase = "convert -quality 70 -units PixelsPerInch -density 150 -antialias -colorspace RGB -strip";
$tot = count($ads);
foreach ($ads as $i => $ad) {
if (!file_exists($ad) || filesize($ad) == 0) { continue; }
$rawad = escapeshellarg ($ad);
$jpgad = escapeshellarg ($jpgdir . '/' . stripext(basename($ad)) . '.jpg');
if (getext($ad) == 'pdf') {
$cmd = "$cmdbase {$rawad}\[0\] $jpgad";
} else {
$cmd = "$cmdbase {$rawad} $jpgad";
}
echo "\n\n==============================================================\n$cmd\n\n";
passthru($cmd);
echo date('[Y-m-d H:i:s] ') . '[' . ($i +1) . ' of ' . $tot . "]\t" . basename($ad) . "\n";
}
}
prepads();
echo date('[Y-m-d H:i:s] ') . "BEGIN Uploading ads to server...\n";
$cmd = "rsync -rtv --bwlimit=50 {$_ENV['HOME']}/displayads/jpgs/ username@server:/www/htdocs/directoryname/";
passthru($cmd);
echo date('[Y-m-d H:i:s] ') . "DONE Uploading ads to server\n";
?>
i am struggling with this for a while now







Bookmarks