|
[ Autoren gesucht! ]
|
PHP-Homepage.de sucht laufend Autoren für News und Artikel
Interesse?
|
|
 |
|
[Start] [Suche] [Neue Einträge]
| Images Upload | <?php
// [c] 2001 Living Solution - Internet Software [open source]
// www.living-solution.de - info@living-solution.de
// this is the file: conf.inc.php
$scriptname = "upload.php";
$image_upload_path = "/home/httpd/html/living-solution.de/uploaded/";
$image_uploadcount_path = "/home/httpd/html/living-solution.de/uploaded/count.log";
$MAX_UPLOAD_SIZE = 30000;
$countlocation = "frame.php";
function logfile($thisfile)
{
global $image_uploadcount_path;
if($thisfile == "") $thisfile = "none";
// change patch to the logfile!
$file = $image_uploadcount_path;
// -- open logfile -- \\
$filehandle = fopen($file,"r");
$count_names = "";
$count_numbers = "";
$o_count = 0;
$dummy = 0;
// Tests for end-of-file on a file pointer
while (!feof($filehandle))
{
$dummy += 1;
if($dummy > 3) break;
// Gets line from file pointer
$buffer = fgets($filehandle, 4096);
switch ($dummy):
// Strip whitespace from the beginning and end of a string
case 1: $count_names = trim($buffer);
case 2: $count_numbers = trim($buffer);
case 3: break;
endswitch;
}
// closed connection to logfile
fclose($filehandle);
// Strip whitespace from the beginning and end of a string
$found = trim(stristr($count_names, $thisfile));
if( $found == "")
{
$count_names = trim($count_names) . "|" . $thisfile;
$count_numbers = trim($count_numbers) . "|1";
$o_count = 1;
}
else
{
// Split the string with "|"
$a_names = explode("|", $count_names);
$a_numbers = explode("|", $count_numbers);
// Get the number of elements in the array
$a_size = sizeof($a_names);
for($i = 0; $i < $a_size; $i++)
{
if($a_names[$i] == $thisfile)
{
$a_numbers[$i] += 1;
$o_count = $a_numbers[$i];
}
}
// Join array elements with a string
$count_names = implode("|", $a_names);
$count_numbers = implode("|", $a_numbers);
}
// open logfile
$filehandle = fopen($file,"w");
// write to Logfile
fwrite($filehandle, $count_names . "\n" . $count_numbers);
// close connection to logfile
fclose($filehandle);
return $o_count;
}
?>
-- this is the file: form.tpl -->
Upload by Living Solution - www.living-solution.de
// [c] 2001 Living Solution - Internet Software [open source]
// www.living-solution.de - info@living-solution.de
// this is the file: upload.php
include("./conf.inc.php");
include("./form.tpl");
if(!empty($imgfile))
{
if($imgfile!="none")
{
$inf = GetImageSize($imgfile);
$err = false;
// make a check
if($inf)
{
// check for uploaded file type
$inf[2] = intval($inf[2]);
if (($inf[2]!=1) && ($inf[2]!=2))
{
$err = true;
$TPL_errmsg = "Das Bild muss das Dateiformat GIF oder JPG haben!";
}
else
{
// check for file size
if ( intval($imgfile_size)>$MAX_UPLOAD_SIZE)
{
$err = true;
$TPL_errmsg = "Die Dateigröße des Bildes ist zu groß!";
}
}
}
else
{
$err = true;
$TPL_errmsg = "Das Bild muss das Dateiformat GIF oder JPG haben!";
}
if (!$err)
{
// countdata
$id = logfile("uploaded");
// really save this file
$ext = ($inf[2]==1)?".gif":".jpg";
$fname = $image_upload_path.$id.$ext;
if(file_exists($fname))
unlink ($fname);
copy($imgfile,$fname);
$uploaded_imgfile = $id.$ext;
$imgfile_uploaded = true;
echo "Uploaded: ".$uploaded_imgfile;
}
else
{
// there is an error
unset($file_uploaded);
echo $TPL_errmsg;
}
}
}
?> |
|