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);
?>