SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    opendir() problem

    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

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    What does "$_ENV['HOME'] . '/displayads/' " output?
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $_ENV['HOME'] is basically just the home directory ...and '/displayads' is the directory previously made in this script with "mkdir"

  4. #4
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It sounds like your script doesn't have permissions to access that directory. Make the directory 777 in your ftp client and see if you still get the error.

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nmpku View Post
    $_ENV['HOME'] is basically just the home directory ...and '/displayads' is the directory previously made in this script with "mkdir"
    Yes but what does $_ENV['HOME'] output. Are you sure it is outputting "/home/ebrad/" and not something else? It isn't uncommon for PHP to be running under a different user.

    I bet if you remove the error suppression from mkdir you will get an error.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Logic - you were right....apparently it was blank. i coded the full path in and no more errors. However, now it is not pulling in the information...am i correct in thinking that this is most likely a permissions problem?

  7. #7
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok...so this problem is solved, kind of..will post my new problem in a separate topic


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •