Page 3 of 11
Re: Newb advice
Posted: Fri Sep 04, 2009 6:04 pm
by Mirge
MiniMonty wrote:jackpf wrote:Btw, you could do this in like one line if you use implode().
Forgive the pun but... care to expand on that ?
Here's the closest version I could come up with, that is much shorter...
Code: Select all
<?php
function f($i) { return '"' . $i . '"'; }
$filesArray = glob("/home/mike/Pictures/*");
$filesString = '[' . join(", ", array_map("f", $filesArray)) . ']';
print "$filesString\n";
?>
If there's a way to use JUST implode() or join()... I'd definitely love to learn how.
Re: Newb advice
Posted: Fri Sep 04, 2009 6:46 pm
by jackpf
Code: Select all
$array = glob('/home/mike/Pictures/*');
echo '["'.implode('", "', $array).'"]';

Re: Newb advice
Posted: Sat Sep 05, 2009 1:43 am
by Mirge
jackpf wrote:Code: Select all
$array = glob('/home/mike/Pictures/*');
echo '["'.implode('", "', $array).'"]';

Beautiful

Re: Newb advice
Posted: Sat Sep 05, 2009 5:21 am
by MiniMonty
Yeah - beautiful.
Thanks for that.
Re: Newb advice
Posted: Sat Sep 05, 2009 7:06 am
by jackpf
Lol no problem.
Re: Newb advice
Posted: Sat Sep 05, 2009 2:09 pm
by MiniMonty
Just to say thanks all.
In 24 hours having never really had anything to do with PHP I've got a script which will upload files,
filter by size and type, rename to a number convention and move them, then output an array to
a seperate .txt file for flash to
very easily read. Finished article attached.
Many hands make light work...
Thanks and Best wishes
Monty
Code: Select all
<?php
define ("MAX_SIZE","100");
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
if(isset($_POST['Submit']))
{
$image=$_FILES['image']['name'];
if ($image)
{
$filename = stripslashes($_FILES['image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
echo '<h1>Only .jpg files allowed !</h1>';
$errors=1;
}
else
{
$size=filesize($_FILES['image']['tmp_name']);
if ($size > MAX_SIZE*1024)
{
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
}
$groovy = sizeof(glob("/path/to/directory/uploads/*"));
$groovy = ++$groovy;
print $groovy;
$image_name=$groovy.'.'.$extension;
$newname="uploads/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}}}}
if(isset($_POST['Submit']) && !$errors)
{
echo "<h1>File Uploaded Successfully!</h1>";
}
$array = glob('uploads/*');
$myFile = "gallarray.txt";
$fh = fopen($myFile, 'w+') or die("can't open file");
$stringData = '["'.implode('", "', $array).'"];';
fwrite($fh, $stringData);
fclose($fh);
?>
Re: Newb advice
Posted: Sat Sep 05, 2009 3:30 pm
by jackpf
Your indentation (or lack of) is horrible

Re: Newb advice
Posted: Sat Sep 05, 2009 4:22 pm
by Mirge
jackpf wrote:Your indentation (or lack of) is horrible

Agreed. Play with Python for a week & then go back to PHP (or PHP and Python)...

Re: Newb advice
Posted: Sat Sep 05, 2009 4:32 pm
by MiniMonty
jackpf wrote:Your indentation (or lack of) is horrible

I'm a designer - I like straight lines and justified text !
Also I'm working on a Mac with SimpleText which is, clue in the title, Simple.
What's the convention for indentation ?
I'm also starting to think I may have been too clever for me own good because Flash doesn't like importing
my beautifully formatted array. I think it may prefer it just comma delimited:
uploads/1.jpg,uploads2.jpg,uploads3.jpg etc
Working on it though...
Re: Newb advice
Posted: Sat Sep 05, 2009 4:39 pm
by jackpf
Well, what do you think looks neater?
this
Code: Select all
if($condition)
{
echo 'do something';
some_function();
}
if(something_else)
{
//do something
}
switch($a_var)
{
case 'foo':
//blah
break;
case 'bar':
//baz
break;
}
class foo
{
public
$a,
$b;
public static function bar()
{
echo 'hello';
}
}
Or this:
Code: Select all
if($condition)
{
echo 'do something';
some_function();
}
if(something_else)
{
//do something
}
switch($a_var)
{
case 'foo':
//blah
break;
case 'bar':
//baz
break;
}
class foo
{
public
$a,
$b;
public static function bar()
{
echo 'hello';
}
}
Re: Newb advice
Posted: Sat Sep 05, 2009 4:48 pm
by Mirge
jackpf wrote:Well, what do you think looks neater?
this
Code: Select all
if($condition)
{
echo 'do something';
some_function();
}
if(something_else)
{
//do something
}
switch($a_var)
{
case 'foo':
//blah
break;
case 'bar':
//baz
break;
}
class foo
{
public
$a,
$b;
public static function bar()
{
echo 'hello';
}
}
Or this:
Code: Select all
if($condition)
{
echo 'do something';
some_function();
}
if(something_else)
{
//do something
}
switch($a_var)
{
case 'foo':
//blah
break;
case 'bar':
//baz
break;
}
class foo
{
public
$a,
$b;
public static function bar()
{
echo 'hello';
}
}
Ohh, ohh can i vote?? Well I'm going to anyway, THE LATTER... indention makes readability much better.
Re: Newb advice
Posted: Sat Sep 05, 2009 5:19 pm
by MiniMonty
Yeah - point taken...
Don't forget the "big fat newb" tag that I come with.
What are the colours telling me ?
Re: Newb advice
Posted: Sat Sep 05, 2009 5:30 pm
by jackpf
The colours make it nice and pretty.
Re: Newb advice
Posted: Sat Sep 05, 2009 5:39 pm
by MiniMonty
jackpf wrote:The colours make it nice and pretty.
Have you ever had a look at Flash ?
You'd see through AS3 (the latest incarnation of it's language) in a minute.
It can do some cool things. Especially (as I am learning) when it's hooked up to a back end
that does cool things too.
Re: Newb advice
Posted: Sat Sep 05, 2009 7:00 pm
by jackpf
The only thing I've ever made in flash is an animation of someone shooting them self in the head
