FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » randomly sorting files in php
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
where to put the binaries was Re: getting perl and php to talk to each other [message #180716 is a reply to message #180643] Thu, 14 March 2013 10:11 Go to previous messageGo to previous message
Cal Dershowitz is currently offline  Cal Dershowitz
Messages: 36
Registered: February 2013
Karma:
Member
On 03/07/2013 12:43 PM, The Natural Philosopher wrote:

> a passing familiarity with package management is not a requirement for
> running PHP or posting in this NG.
>
> NOr is installation of php development files and utilities a requirement
> fora basic LAMP setup.
>
>

NP, I've been reading you for a while now. Did you give me the name of
a newsgroup where they consider webstuff ontopic?

I'm rather convinced that scripting languages are my meal ticket this
month, so much so that I'm making it happen with my rudimentary
webtools. This is what I call output:

http://merrillpjensen.com/food_4.html

This is a powerful medium, where one can intermix binaries and text. My
problem now is that it's not a discrete medium without me attending
endlessly to obfuscations with files that I would much just rather have
as themselves, and the only way you can see them is if php lets you with
an authentication level equal to my level of give a crap.

It's been a while since I did a source listing, so I would like to do
so, now that I can ask better questions.

In my line of work, I find myself taking a lot of pictures, because it
shows what I do for my clients. My clients are honest to God Amis whose
privacy is a matter for me to stake my integrity on, and I have enough
of them that I know that their preferences to privacy vary, depending
mostly on age, btw. Little bit on class. whatevs.

The rub is that I need to be able to show what I do to market the things
that I do. These are the scripts I'm using to pull it off now:

I run a bash script to handle the images that get chosen from my camera:

$ cat nikon_bash3.sh
#!/bin/bash

set -e
PARENTDIR='cleaning'
DIR='images1'
cd ${PARENTDIR}
mkdir -p $DIR
cp *.JPG $DIR
cd $DIR
ls -l
mogrify -resize 800x600! *
rename 'y/A-Z/a-z/' *.JPG
ls -l
cd ..
cd ..
pwd
sudo fredify2.sh
$

I have several versions of this. Very vanilla.

$ cd cleaning
$ cat food_ftp1.pl
#!/usr/bin/perl -w
use strict;
use 5.010;
use Net::FTP;
use HTML::Entities;
use File::Basename;
use Cwd;

# diamond bracket in paragraph mode declared at top scope
$/ = "";

## usage needs 1 arg from argv my_ftp

#identity and config
my $ident = 'my_ftp.txt';
my ( $config, $domain );
$config = do($ident);
unless ($config) {
die("read error: $!") if $!;
die("parse error: $@") if $@;
}
$domain = $config->{ $ARGV[0] };
die("unknown domain: $ARGV[0]") unless $domain;

# get name of directory
my $dir = cwd;
print "dir is $dir \n";
my $word = basename($dir);
print "word is $word \n";

# get files
my $path = "images1/";
my @files = <$path*>;
print " files are @files\n";

#dial up the server
my $ftp = Net::FTP->new( $domain->{domain}, Debug => 1, Passive => 1 )
or die "Can't connect: $@\n";
$ftp->login( $domain->{username}, $domain->{password} )
or die "Couldn't login\n";
$ftp->binary();

# get files from remote root that end in html:
my @remote_files = $ftp->ls();

# make unique .html choice
my @matching = map /${word}_(\d+)\.html/, @remote_files;
print "matching is @matching\n";
push( @matching, 0 );
@matching = sort { $a <=> $b } @matching;
my $winner = pop @matching;
my $newnum1 = $winner + 1;
my $word2 = "${word}_$newnum1";
print " new word is $word2\n";
my $html_file = "${word2}.html";
print "html file is $html_file\n";

#make directory in images to correspond

$ftp->cwd("images/")
or die "Cannot change working directory ", $ftp->message;
$ftp->mkdir("${word2}/")
or warn "Cannot create directory ", $ftp->message;
$ftp->cdup();

# create file for html stubouts
open( my $fh, '>', $html_file )
or die("Can't open $html_file for writing: $!");

my $header = "template_stuff/header1.txt";

# write in the header
open( my $gh, '<', $header ) or die("Can't open: $!");

while (<$gh>) {
print $fh $_;
}

my $h1 = 'Resolving conflicts';
my $h2 = 'and moving forward';
print $fh "<h1>$h1</h1>\n";
print $fh "<h2>$h2</h2>\n";

#create template outside loop

my $template = <<'TEMPLATE';
<img src="/images/%s"/>

<p>%s</p>
TEMPLATE

open my $CAPTIONS, "<", "food1.txt" or die "file not there\n";

$ftp->cwd("/images/${word2}/") or die "cwd failed $@\n";

# main control
for my $name (@files) {
print "name is $name\n";
my $remote_file = basename($name);
print "remote is $remote_file\n";
$ftp->put( $name, $remote_file ) or die "put failed $!\n";

# captions
my $caption = <$CAPTIONS>;
$caption = encode_entities($caption);
printf $fh $template, "${word2}/" . $remote_file, $caption;
}

# write in the footer
my $footer = "template_stuff/footer1.txt";
open( my $hh, '<', $footer )
or die("Can't open: $!");

while (<$hh>) {
print $fh $_;
}

close $fh;
$ftp->pwd();
$ftp->ls();
$ftp->cdup() or die "cdup failed $@\n";
$ftp->cdup() or die "cdup failed $@\n";
$ftp->put($html_file) or die "put failed $@\n";

$

This has so far been my home-cooked perl version of static web dev, but
I want to see if php can obviate all the go***a%n filing-about that you
have to do to maintain the privacies of the the binaries shown. These
images are my shack so I don't care so much anymore. I also use this
tool chain to lay down the law with people a bit; it's a very direct medium:

http://merrillpjensen.com/cleaning_1.html

Q1) How do I design a website where the binaries aren't there for the
taking unless php thinks you have done some act of authentication to see
them?

Q2) What's a good first book for php?
--
Cal
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to avoid the use of session variables in this script
Next Topic: all done
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 14:21:12 GMT 2024

Total time taken to generate the page: 0.04613 seconds