Jump to content

Upload file then put it's name and url in mysql?


Cory94bailly

Recommended Posts

I know it's possible but I'm having lots of problems..

 

Recent.php:

 

<title>Add/Delete Recent Configs/Work</title>
<a href="../">Home</a>
   
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</form> 

 

 

Upload.php:

 

<?php
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

    if (file_exists("../uploaded/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      $url = '../uploaded/';
  

  move_uploaded_file($_FILES["file"]["tmp_name"],
      "$url/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "../uploaded/" . $_FILES["file"]["name"];
      }
    }


?>

 

 

 

And I'm stuck from there..

 

I know how to get it to actually upload and stuff but I just can't find out how to put down it's url and name into mysql straight after uploading..

 

 

 

And also, I want to know how to make it so when they upload it, the server gives the files a unique, random name and saves it.. But then, how do I get it to be downloaded as the actual file name?

 

/Confusing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.