Avatar billede sturman Nybegynder
24. februar 2003 - 10:50 Der er 9 kommentarer og
1 løsning

pop-up not popping up

well i've fixed some of the bugs so now it uploads, i have two probs i cannot seem to get passed. one of them is that some pictures i upload dont seem to fully go over, only part of the picture. but the main prob is that the pop-up link i create does not pop-up. am i missing something?? here's the script that does it, or not as the case maybe. as always feel free to reply in danish.

<?php
/*
-------------------Header------------------

Description:
    Demonstrate how to upload a file and then later displaying a list of the
    images already uploaded providing a link. this will open in a new window,
    sized 800*650. This is done with Javascript.
   
----------------END OF HEADER----------------
*/
require_once("db.file");


/*
    -Loop through all the uploaded files submitted
    -Functions used:
   
    -is_uploaded_file( string name ) : Returns TRUE if the file named by
    filename was uploaded via HTTP POST.
    -move_uploaded_file( string filename, string destination ) : This function
    checks to ensure that the file designated by filename is a valid upload file (meaning
    that the file was uploaded vis PHP's HTTP POST mechanism. If the file is valid,
    it will be moved to the filename given by destination.
*/

function move_files()
{
    global $HTTP_POST_FILES, $file_dir; // make the whole array global
    $file_dir="/var/www/html/uploads/"; //path to upload dir

    foreach ( $HTTP_POST_FILES as $file_name => $file_array )
{
    if( is_uploaded_file ($file_array['tmp_name'] ) )
    {
    move_uploaded_file($file_array['tmp_name'], "$file_dir".$file_array['name'] );
    }
}
}

/*
    -This function takes care of inserting the new image and caption into
    the images table
    -Calls move_files() before inserting into table, better to have a stay image
    with no entry in the table than having an entry in the table and no image to go
    with it.
    -Assumes that table "images" exsits
*/

function commit()
{
    global $link, $img_name, $img_caption;
    // this function take the current time in seconds from Epoch(Jan 1, 1970 00:00:00)
    $time_stamp=time();

    move_files();

    //insert new row into images
    $insert_query="INSERT INTO images (img_name, img_caption, date_auto) VALUES ('$img_name', '$img_caption', '$time_stamp')";

    send_query($insert_query,$link);
}

/*
Some checking needs to be done here to make sure that these vars conatin a value.
can be done with Javascript (then no checking needs to be done here as then we are sure that
the vars contain something) field type script..
*/

$img_name = $HTTP_POST_FILES['imageupload'] ['name'];
$img_caption = $HTTP_POST_VARS['caption'];
echo 'img_name : '.$img_name;
echo '<br>img_caption : '.$img_caption;

//only commit this page has been submitted
if($HTTP_POST_FILES['imageupload']['name']!=NULL)
{
    commit();
}

?>

<script language="javascript">
<!--
function showimage(image_loc)
{
window.open(image_loc, 'mainpage','toolbar=yes, location=no, directions=no, status=no,menubar=yes,scrollbars=yes,resizable=no, width=800, height=650');
}
//-->
</script>



<html>
<head>
<title>File uploading and displaying them</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="POST" enctype="multipart/form-data" name="uploadform">
Image:<input type="file" name="imageupload"><br><br>
Caption: <input type="text" name="caption"><br><br>
<input type="submit" name="submit" value="Send Image">
</form>
<br>
<p>
Here's a list of all the images uploaded:
<?php

    echo 'File Dir: '.$file_dir;
    $query="SELECT * from images ORDER by date_auto DESC"; // newest reviews at top
    $data=send_query($query, $link);
    echo '<ol>'; // start ordered list
    for ($i=0;$i < mysql_num_rows ($data);$i++)
    {
        //get all values needed for output
        /*
        function used : mysql_result (resource result, int row, mixed field)
        mysql_result() returns the contents of one cell from a mysql result set.
        The field argument can be fields offset, or the fields name, or the fields
        tabel dot field name (tablename.fieldname) .
        */

        $img_name = mysql_result($data, $i, "img_name" ) ;
        $img_caption =mysql_result($data, $i, "img_caption") ;
        $time = mysql_result($data, $i, "date_auto");

        //if there are any newlines in the caption then convert these to <br> tags

        $img_caption = nl2br ($img_caption);
       
        // Create the output.
        // OUTPUT: 1. link : <date><newline>bulletpoint>caption
        // DATE FORMAT: Wed 19/02/03 12:53:16 AM format is created by date()

        echo '<li><a href ="java script:showimage('.$file_dir.$img_name.') ">'.$img_name. '</a> added : '. date("D d/m/y h:i:s A", $time).'       
                <ul>
                    <il><em>'.$img_caption.'</em></il>
                    </ul>
                    <il><br>';
        }
        echo '</ol>'; // end ordered list
?>
</p>
</body>
</html>
Avatar billede sturman Nybegynder
24. februar 2003 - 10:54 #1
sorry but i was not sure if i should stick this in the java section or not... the pop-up is done with javascript as you probably noticed.
Avatar billede tangveje Nybegynder
24. februar 2003 - 11:42 #2
Ved ikke om dette hjælper, men har ændret et par ting, prøv om det hjalp

<?php
/*
-------------------Header------------------

Description:
    Demonstrate how to upload a file and then later displaying a list of the
    images already uploaded providing a link. this will open in a new window,
    sized 800*650. This is done with Javascript.
 
----------------END OF HEADER----------------
*/
require_once("db.file");


/*
    -Loop through all the uploaded files submitted
    -Functions used:
 
    -is_uploaded_file( string name ) : Returns TRUE if the file named by
    filename was uploaded via HTTP POST.
    -move_uploaded_file( string filename, string destination ) : This function
    checks to ensure that the file designated by filename is a valid upload file (meaning
    that the file was uploaded vis PHP's HTTP POST mechanism. If the file is valid,
    it will be moved to the filename given by destination.
*/

function move_files()
{
    global $HTTP_POST_FILES, $file_dir; // make the whole array global
    $file_dir="/var/www/html/uploads/"; //path to upload dir

    foreach ( $HTTP_POST_FILES as $file_name => $file_array )
{
    if( is_uploaded_file ($file_array['tmp_name'] ) )
    {
    move_uploaded_file($file_array['tmp_name'], "$file_dir".$file_array['name'] );
    }
}
}

/*
    -This function takes care of inserting the new image and caption into
    the images table
    -Calls move_files() before inserting into table, better to have a stay image
    with no entry in the table than having an entry in the table and no image to go
    with it.
    -Assumes that table "images" exsits
*/

function commit()
{
    global $link, $img_name, $img_caption;
    // this function take the current time in seconds from Epoch(Jan 1, 1970 00:00:00)
    $time_stamp=time();

    move_files();

    //insert new row into images
    $insert_query="INSERT INTO images (img_name, img_caption, date_auto) VALUES ('$img_name', '$img_caption', '$time_stamp')";

    send_query($insert_query,$link);
}

/*
Some checking needs to be done here to make sure that these vars conatin a value.
can be done with Javascript (then no checking needs to be done here as then we are sure that
the vars contain something) field type script..
*/

$img_name = $HTTP_POST_FILES['imageupload'] ['name'];
$img_caption = $HTTP_POST_VARS['caption'];
echo 'img_name : '.$img_name;
echo '<br>img_caption : '.$img_caption;

//only commit this page has been submitted
if($HTTP_POST_FILES['imageupload']['name']!=NULL)
{
    commit();
}

?>

<html>
<head>
<title>File uploading and displaying them</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript">
<!--
function showimage(image_loc)
{
window.open(image_loc, 'mainpage','toolbar=yes, location=no, directions=no, status=no,menubar=yes,scrollbars=yes,resizable=no, width=800, height=650');
}
//-->
</script>

</head>

<body>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="POST" enctype="multipart/form-data" name="uploadform">
Image:<input type="file" name="imageupload"><br><br>
Caption: <input type="text" name="caption"><br><br>
<input type="submit" name="submit" value="Send Image">
</form>
<br>
<p>
Here's a list of all the images uploaded:
<?php

    echo 'File Dir: '.$file_dir;
    $query="SELECT * from images ORDER by date_auto DESC"; // newest reviews at top
    $data=send_query($query, $link);
    echo '<ol>'; // start ordered list
    for ($i=0;$i < mysql_num_rows ($data);$i++)
    {
        //get all values needed for output
        /*
        function used : mysql_result (resource result, int row, mixed field)
        mysql_result() returns the contents of one cell from a mysql result set.
        The field argument can be fields offset, or the fields name, or the fields
        tabel dot field name (tablename.fieldname) .
        */

        $img_name = mysql_result($data, $i, "img_name" ) ;
        $img_caption =mysql_result($data, $i, "img_caption") ;
        $time = mysql_result($data, $i, "date_auto");

        //if there are any newlines in the caption then convert these to <br> tags

        $img_caption = nl2br ($img_caption);
     
        // Create the output.
        // OUTPUT: 1. link : <date><newline>bulletpoint>caption
        // DATE FORMAT: Wed 19/02/03 12:53:16 AM format is created by date()

        echo '<li><a href="#" onclick="showimage('.$file_dir.$img_name.') ; return false ;">'.$img_name. '</a> added : '. date("D d/m/y h:i:s A", $time).'<ul><il><em>'.$img_caption.'</em></il></ul><il><br>';
        }
        echo '</ol>'; // end ordered list
?>
</p>
</body>
</html>
Avatar billede sturman Nybegynder
24. februar 2003 - 13:37 #3
still no go. however i do get an '#' in the addressbar after i click on the link. and that's the only change
Avatar billede fangel Nybegynder
24. februar 2003 - 16:41 #4
look's like you forgot a litle thing when calling the JS function... ;)

this:
echo '<li><a href="#" onclick="showimage('.$file_dir.$img_name.') ; return false ;">'.$img_name. '</a> added : '. date("D d/m/y h:i:s A", $time).'<ul><il><em>'.$img_caption.'</em></il></ul><il><br>';

should be
echo "<li><a href=\"#\" onclick="showimage(\'" . $file_dir . $img_name . "\') ; return false ;\">$img_name</a> added : " . date("D d/m/y h:i:s A", $time) . "<ul><il><em>$img_caption</em></il></ul><il><br>";

you whould have noticed the error if you'd checked your JS debugger ;)

Morten
Avatar billede fangel Nybegynder
24. februar 2003 - 16:43 #5
btw, the thing missing was the ' around the parrameter when calling the JS function ;) hence the extra \' in the function call... and changed the 's to "s as I tend to like them better ;) no special reeason for that change ;)
Avatar billede sturman Nybegynder
24. februar 2003 - 17:19 #6
got parse errors from that dea pq
Avatar billede sturman Nybegynder
24. februar 2003 - 17:20 #7
cannot seem to locate them.. if it make any difference i am running on RedHat linux 8 php 4.2.2
Avatar billede fangel Nybegynder
24. februar 2003 - 17:54 #8
sorry... my fault... this work's...

echo "<li><a href=\"#\" onclick=\"showimage('" . $file_dir . $img_name . "') ; return false ;\">$img_name</a> added : " . date("D d/m/y h:i:s A", $time) . "<ul><il><em>$img_caption</em></il></ul><il><br>";

eg:
http://exp.mfa.ath.cx/sturman.php

Morten
Avatar billede sturman Nybegynder
25. februar 2003 - 09:19 #9
ok i pasted in that code you wrote. i can see that youe eg works - but for some reason i get FILE NOT FOUND and it writes the direct path to me uploads dir eg /var/www/html/uploads/mypicture.jpeg. not found on this server. but when i check the folder its in there...
Avatar billede sturman Nybegynder
26. februar 2003 - 10:49 #10
accepted your answer dea. still cannot get mine working but will give you the points for your working example. 8]-)
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