Avatar billede donandres Nybegynder
10. februar 2005 - 23:00 Der er 2 kommentarer og
1 løsning

noget galt i scriptet

hej eksperter...

kan I se hvad der er galt i dette script?
det er et galleri, hvor man nederst kan uploade billeder... men uploadfunktionen virker ikke... mapperne er chmod 777.

default.php (filen som vises i browseren)

<?
include("functions.inc");
?>
<html>
<head>
<title>Galleri</title>
<style>
BODY            { color:#000000; font-size:11px; font-weight:bold; font-family: Tahoma, Arial;}
A:link            { color:#000000; text-decoration:underline; font-weight:bold;}
A:visited        { color:#000000; text-decoration:underline; font-weight:normal;}
A:hover            { color:#000000; text-decoration: overline;}
h1                { font-size:15px;}
</style>
</head>
<body>
<h1>Galleri</h1>
<div align="center">
<?
getImages($firstImage);
?>
<BR>
</div>
<span style="font-weight:normal;"><?php
/* Destination of Upload files..use / insted of \\ in UNIX */
define("DESTINATION1", "/galleri/images");
define("DESTINATION2", "/galleri/images");

/* Number of Upload files */
define("UPLOAD_NO", 1);


if($REQUEST_METHOD!="POST")
{
print "<form enctype=\"multipart/form-data\" method=post>\n";
print "<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\"
value=\"3000000\">\n";
print "Upload Billede<br><br><br>";
for($i=1; $i<=UPLOAD_NO; $i++)
{
print "Billede $i&nbsp;&nbsp;&nbsp;&nbsp;";
echo "<input type=file name=infile$i>&nbsp;&nbsp;&nbsp;&nbsp;";

if($i%2==0)
print"<br>";
}
echo "<br><br><input type=submit value=upload></form>\n";
}
else
{
/* handle uploads */
$noinput = true;
for($i=1; $noinput && ($i<=UPLOAD_NO); $i++)
{
if(${"infile".$i}!="none") $noinput=false;
}
if($noinput)
{
print "<big><B>Error uploading. Try again.</B></big>";
exit();
}
echo("<p align='center'><b><font size='4'>Successfully
Uploaded<br>");

echo("<table border='1' width='84%' height='52'
bordercolorlight='#008080' bordercolordark='#008080'>
<tr>
<td width='14%' bgcolor='#008000' height='21'><font
color='#FFFFFF'><b>Sn</b></font></td>
<td width='52%' bgcolor='#008000' height='21'><font
color='#FFFFFF'><b>Filename</b></font></td>
<td width='34%' bgcolor='#008000' height='21'><font
color='#FFFFFF'><b>Size</b></font></td>
</tr>");

for($i=1; $i<=UPLOAD_NO; $i++)
{

$just=filesize(${"infile".$i});
$fp_size[i] = $just;

if(${"infile".$i}!="none")
{
copy(${"infile".$i}, DESTINATION1.${"infile".$i."_name"});
copy(${"infile".$i}, DESTINATION2.${"infile".$i."_name"});
unlink(${"infile".$i});
{
echo("<tr>
<td width='14%' height='19'>$i</td>
<td width='52%' height='19'>${"infile".$i."_name"}</td>
<td width='34%' height='19'>$fp_size[i]</td>
</tr>
");
}
}
}
echo "</table>";
}
?>
</span>
</body>
</html>



og functions.inc

<?
//----  Settings Start ---\\
// Image Information
$imageWidth=100;
$imageHeight=100;

// Table Layout
$rows=3;
$cols=5;

//Image path
$libery="/galleri/images/"; // remember to finish with /

// Settings Stop----------//

$viewNum=$cols*$rows;
if(!$firstImage){ // so it works if you just enter default.php and show the pictures without having to define the variables in the path
        $firstImage=1;
}
function getImages($firstImage){
    global $viewNum, $imageWidth, $imageHeight,$cols,$libery;  //insures that the function gets the variables
    $handle=opendir($libery); //opens directory
    while($file=readdir($handle)){ // reads the directory
        $extension=substr($file,-4); // gets the extension of the files
        if(($extension == ".jpg") || ($extension == ".gif") || ($extension == ".png") ){ // checks for image files
            $all[]=$file;  //adds positive results to the archive
        }
    }
    $colscounter=0; // variable that controls the tablebuilding system below
    $firstImage--; // variable that insures that the first image is being showed. Case: It looks best if the links begins with 1 but the array begins with 0
    if(isset($all)){  // if array is set build the table
        print "<table>";
        for($i=$firstImage; $i < $firstImage+$viewNum; $i++){
            if($all[$i]){ // checks for rinning dry of imges
                if($i==$firstImage + $colscounter*$cols){ // if true: new row
                    $colscounter++;
                    print "<tr>";
                } // add the image
                print "<td><a href='".$libery."".$all[$i]."'><img src='".$libery."".$all[$i]."' border='0' width='$imageWidth' height='$imageHeight' alt='Click to Enlarge'></a></td>";
            }
            else{ // stop if no more images
                break;
            }
        }
        print "</table><br>";
        $num=count($all);  //number of pictures in actual libery
        makeList($num); // function to make the links list
    }
    else{
        print "Der var desværre ingen billeder i dette bibliotek<br><a href='java script:history.back()'>Go Back</a>";
    }
}
function makeList($num){
    global $libery, $firstImage, $viewNum; //insures that the function gets the variables
    $numLinks = $num / $viewNum; // finds the number og links to be maked
    for($a=0; $a < $numLinks;$a++){
            $start=$a*$viewNum+1;  //adds 1 because then the links begins with ex. number 1-10 and 11-20 instead of 0-10 and 10-20
            $finish=$a*$viewNum+$viewNum;
            if($finish>$num){ // insures that the final link returns the right amount of pictures instead of to much
                $finish=$num;
            }
        if(($firstImage >= $start) && ($firstImage < $a * $viewNum+$viewNum)){ // if true: makes no link because you already are on the page
            print "$start - $finish</a>&nbsp;&nbsp;";
        }
        else{ // makes the link
            print "<a href='default.php?libery=$libery&firstImage=$start'>$start - $finish</a>&nbsp;&nbsp;";
        }
    }
}
?>
Avatar billede Slettet bruger
11. februar 2005 - 00:37 #1
"Virker ikke" er en meget vag beskrivelse, som det er umuligt at fejlfinde ud fra. Hvad sker der, når du prøver? Får du en fejlbesked?

Derudover bør du skifte til et script, der ikke kræver register_globals.
Avatar billede donandres Nybegynder
11. februar 2005 - 11:11 #2
fejlen er at jeg ikke kan uploade et billede..

kan dette script ikke laves om så det ikke kræver register_globals?
Avatar billede donandres Nybegynder
14. marts 2005 - 13:43 #3
jhg
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester