Avatar billede sturman Nybegynder
23. februar 2003 - 15:55 Der er 7 kommentarer og
1 løsning

getting url/< not found error ??

sorry people but writing in english cos my written danish usless. but feel free to reply in danish, no probs reading it.

Ok for some reason i am getting an error when i try and upload an image. tells me NOT FOUND the requested url/< was not found on this server. and underneath all that it tells me my version of apache and default port 80. am running on RH8 php 4.2.2

am basically tryin to upload a picture and create a link to that picture so when i click the link the picture pops up in a new window. if you have a better script for doin this feel free to post that cos i really need this to work.


here's me code with comments to help you understand what's what:

<?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 (imageid, image_name, 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'];

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']?>" metod="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

    $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, "image_name" ) ;
        $img_caption =mysql_result($data, $i, "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 swaxi Nybegynder
23. februar 2003 - 16:05 #1
for me it looks like the line :
    form action="<?=$_SERVER['PHP_SELF']?>"
doesnt get parsed ... try with
    form action="<?php echo $_SERVER['PHP_SELF']; ?>"
Avatar billede tangveje Nybegynder
23. februar 2003 - 16:09 #2
Eller du kan sætte short_open_tags til on i /etc/php.ini den er vist som standard sat til off i RH8
Avatar billede sturman Nybegynder
23. februar 2003 - 16:18 #3
the reason why it did not work the way i did was due to the short tags werent on. but swaxi's solution did the trick so if you want the points swaxi post an answer. cheers to the both of you. tangveje, will give you some too if you put up an ans.
Avatar billede sturman Nybegynder
23. februar 2003 - 16:18 #4
at least if anyone is lookin for an upload script they now have one.
Avatar billede tangveje Nybegynder
23. februar 2003 - 16:19 #5
:)
Avatar billede sturman Nybegynder
23. februar 2003 - 16:21 #6
woops gave all the points to tangveje. sorry about that swaxi no clue what i was doin there.
Avatar billede tangveje Nybegynder
23. februar 2003 - 16:23 #7
Avatar billede sturman Nybegynder
23. februar 2003 - 16:24 #8
thanks mate...
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