This post is somewhat in regards to my previous post, but I've decided to go a different route.

I am trying to upload an image to my server and to my MySQL database.

I have a form page where the info is entered and I now have an upload.php file to process the form.

Everything processes fine EXCEPT the filename is getting transferred as the tmp name e.g. - /var/tmp/phplS7IZB

It should look like this - 1_9_2006.jpg

Is there a way I can change the script below to get rid of the temp name and insert the actual file name into the database?

<?php
if ($submit) {

//Database Connection
   include $_SERVER['DOCUMENT_ROOT'] . '/db.inc.php';

  $sql = "INSERT INTO images (category,title,image,submitted,approve) VALUES ('$category','$title','$image','$submitted','$approve')";

  $result = mysql_query($sql);


echo "<br><br><h1>Thank you for your image!</h1> We will make sure your joke is not obscene or in any way against our terms prior to being approved.<br><br>  <a href='http://www.blondesandrednecks.com/index.php'>Continue</a>
&nbsp;&nbsp;|&nbsp;&nbsp;<a href='http://www.blondesandrednecks.com/visitorimage.php'>Enter another image</a><br><br>";

} 

// Where the file is going to be placed 

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

?>

    I think the issue is with basename() in your $target_path assignment. You should try removing the basename() function and see how that works.

    $target_path = "uploads/" . $_FILES['uploadedfile']['name'];
    
      Write a Reply...