Hi Guys,
I'm writing a client area in PHP / MySQL backend - so far everything is tickety boo.
Login, Registration, Profile and Chat area all work fine.
I'm making a "documents" area for clients to upload & view their own files.
I'm using "uploadify" to make the upload process a bit more seamless. Uploadify itself is working perfectly, and the files are uploading correctly. Great. So the problem?
I'd like to insert some data into the MySQL DB upon a successful file upload.
Documents.php:
As you can see below, i'm using
to insert into the DB at time of successful upload.
However, it's not working. Any ideas?
Uploadify.php
I'm writing a client area in PHP / MySQL backend - so far everything is tickety boo.
Login, Registration, Profile and Chat area all work fine.
I'm making a "documents" area for clients to upload & view their own files.
I'm using "uploadify" to make the upload process a bit more seamless. Uploadify itself is working perfectly, and the files are uploading correctly. Great. So the problem?
I'd like to insert some data into the MySQL DB upon a successful file upload.
Documents.php:
PHP:
<?php
session_start();
if(!isset($_SESSION['username'])){
header( 'Location: login.php' );
}
require('db.php'); // Connect to the database since we'll be needing it later.
// Get Clients ID
$client_ID = mysql_query("SELECT 'client_ID'
FROM 'clients'
WHERE username='".$_SESSION['username']."'");
// Displays all current files
$getDocuments = mysql_query("SELECT * FROM uploads2 WHERE ID='".$client_ID."'");
while($row = mysql_fetch_array($getDocuments, MYSQL_ASSOC))
{
echo "Download: <a href='" . $row['URL'] . "'>" . $row['NAME'] . "</a> | " . $row['SIZE'] . " | " . $row['CONTENT_TYPE'] . "<br /><br />";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Client Documents</title>
<!--UPLOADIFY -->
<link href="./uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="./uploadify/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="./uploadify/swfobject.js"></script>
<script type="text/javascript" src="./uploadify/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : './uploadify/uploadify.swf',
'script' : './uploadify/uploadify.php',
'cancelImg' : './uploadify/cancel.png',
'folder' : './uploads',
'multi': true,
'buttonText': 'Select Files',
'checkScript': './uploadify/check.php',
'displayData': 'speed',
'onAllComplete' : function(){ alert("Thank you. All files have been uploaded successfully."); },
'simUploadLimit': 2
});
});
</script>
<!-- UPLOADIFY END-->
</head>
<body>
<form>
<input id="file_upload" name="file_upload" type="file" />
<a href="javascript:$('#file_upload').uploadifyUpload()">Start Upload</a> | <a href="javascript:$('#file_upload').uploadifyClearQueue()">Clear Queue</a>
</form>
</body>
</html>
As you can see below, i'm using
PHP:
mysql_query("INSERT INTO uploads2(ID, URL, NAME, SIZE, CONTENT_TYPE) VALUES ('$client_ID', '$targetFile', '$fileName', '$fileSize' , '$fileType')");
However, it's not working. Any ideas?
Uploadify.php
PHP:
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
//$fileName = $_FILES['uploadify']['name'];
//$fileSize = $_FILES['uploadify']['size'];
//$fileType = $_FILES['uploadify']['type'];
$fileName = test;
$fileSize = test;
$fileType = test;
// $fileTypes = str_replace('*.','',$_REQUEST['fileext']);
// $fileTypes = str_replace(';','|',$fileTypes);
// $typesArray = split('\|',$fileTypes);
// $fileParts = pathinfo($_FILES['Filedata']['name']);
// if (in_array($fileParts['extension'],$typesArray)) {
// Uncomment the following line if you want to make the directory if it doesn't exist
mkdir(str_replace('//','/',$targetPath), 0755, true);
move_uploaded_file($tempFile,$targetFile);
mysql_query("INSERT INTO uploads2(ID, URL, NAME, SIZE, CONTENT_TYPE) VALUES ('$client_ID', '$targetFile', '$fileName', '$fileSize' , '$fileType')");
//echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
// } else {
// echo 'Invalid file type.';
// }
}
?>
