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>