Jump to content

Upload and insert image - 404 error??


yandoo

Recommended Posts

Hi there,

 

Im trying to  upload an imageto a directory and insert a pointer for that image in a table in my database, i wa so sure the code was correct, but kep getting a 404 error when running the page and trying to upload image.... Heres whats in the browser when i get the error: http://localhost/woodside/%3C?=$_SERVER['PHP_SELF']?>

 

Could anybody take a glance at the code and shed some light on it please????

 

Thank You :)

 

<?php
//image upload test
$file_dir = "C:/wamp/www/Woodside/Images/";
$link_dir = "./images/";
$file_url = "http://localhost/woodside/images/";

if (isset($_POST['submit']))
{
$image_name = $_FILES['image']['name'];
$image_size = $_FILES['image']['size'];
$image_type = $_FILES['image']['type'];
$uploadfile = $file_dir.basename($image_name);
if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) {
   echo "File is valid, and was successfully uploaded.\n";
// Query to insert data
$sql = "INSERT INTO `animaltable` (`Name`, `Type`, `Breed`, `Image`) VALUES ('".$_POST['pname']."', '".$_POST['ptype']."', '".$_POST['breed']."', '".$link_dir.$image_name."')";
echo "$sql<br />";
//mysql_query($sql)or die(mysql_error());

} else {
   echo "Possible file upload attack!\n";
}
// Uncomment these lines if you are having problems
//echo 'Here is some more debugging info:';
//print_r($_FILES);

print "</pre>";
  print "<center>Image path: $file_dir<br>\n";
  print "<center>Image name: $image_name<br>\n";
  print "<center>Image size: $image_size bytes<br>\n";
  print "<center>Image type: $image_type<p><br>\n\n";
      print "<img src=\"$file_url/$image_name\"><p>\n\n";
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST" enctype="multipart/form-data">
Pet Name <input type=text name=pname /><br />
Type <input type=text name=ptype /><br />
Breed <input type=text name=breed /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input type="file" accept=".jpg" size="20" name="image" title="Image Upload" /><br>

<input type="submit" name=submit value="Submit">

</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.