Hi guys. I'm making a file uploading codish thing. And I have a database right. And I want the name of file which is uploaded to go into my database. The problem is that when you upload it doesn't give the name of file rather leaving it blank. Here's part of the upload code:
PHP Code:
<form action="/index.php?page=home" enctype="multipart/form-data" method="post">
<table class="box">
<tbody>
<tr>
<fieldset>
<h2>Browse for your file:<em> required</em></h2>
<div class="file_input_div">
<input type="button" value="Browse »" class="file_input_button" />
<input type="file" name="site_url" class="file_input_hidden" onchange="javascript: document.getElementById('fileName').value = this.value" /></div>
<input type="text" id="fileName" class="file_input_textbox" readonly="readonly" />
<img src="/images/info.png" class="tooltip" title="The URL to your site, eg: www.yoursite.com." />
</fieldset>
</tr>
<tr>
<fieldset>
<h2>What are you uploading?<em> optional</em></h2>
<input id="name" name="site_description" size="30" type="text" class="input_textbox" value="" />
<img src="/images/info.png" class="tooltip" title="Tell us a little about what your uploading." />
</fieldset>
</tr>
</tbody>
<tfoot>
<tr>
<fieldset class="buttons">
<input type="hidden" name="form_key" id="form_key" value="<?php echo $_SESSION['form_key']; ?>" />
<button id="upload_button" name="submit" type="submit" value="Upload Now »">Upload Now »</button>
</fieldset>
</tr>
</tfoot>
</table>
</form>
<?php
$site_id = intval($_GET['id']);
$site = $sites->getSite($site_id);
// Configuration - Your Options
$allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
$max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
$upload_path = './uploads/'; // The place the files will be uploaded to (currently a 'files' directory).
$filename = $_FILES['site_url']['name']; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['site_url']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
// Upload the file to your specified path.
if(move_uploaded_file($_FILES['site_url']['tmp_name'],$upload_path . $filename))
echo 'Sucessfully uploaded file. <a href="/index.php?page=site_view&id=' .$row['site_id'] .'">Here</a>';
else
echo "Error!";
?>
Comment