im using uploadify that can upload multi photos.. now i need to select a client to upload photos.. after choosing a client > next is client profile.. including the "add photo" button which is jquery... my problem is after choosing a client i need to get the clientid then pass it on uploadify... that all process is in that php script... (insert to database > create generate folder to directories > and upload photos)
this is my code.. please HELP ! thanks in advance ~
add_photo.php
<head>
<!--for the gallery-->
<link rel="stylesheet" type="text/css" href="css/jquery.ad-gallery.css">
<script type="text/javascript" src="scripts/jquery.ad-gallery.js?rand=995"></script>
<!--for the uploadify-->
<link href="css/default.css" rel="stylesheet" type="text/css" />
<link href="css/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="scripts/swfobject.js"></script>
<script type="text/javascript" src="scripts/jquery.uploadify.v2.1.0.min.js"></script>
//uploadify:
$("#uploadify").uploadify({
'uploader' : 'scripts/uploadify.swf',
'script' : 'scripts/uploadify.php',
'cancelImg' : 'css/cancel.png',
'folder' : 'images',
'queueID' : 'fileQueue',
'auto' : true,
'multi' : true,
'queueSizeLimit' : 5,
'fileDesc' : 'jpg, gif',
'fileExt' : '*.jpg;*.gif',
'sizeLimit' : '512000',//max size bytes - 500kb
'checkScript' : 'scripts/check.php', //if we take this out, it will never replace files, otherwise asks if we want to replace
'onAllComplete' : function() {
$('#switch-effect').unbind('change');
$('#toggle-slideshow').unbind('click');
galleries[0].slideshow.stop();
start();
}
});
</head>
<body>
<!--uploadify-->
<div style="float:left;">
<div id="fileQueue"></div>
<input type="file" name="uploadify" id="uploadify" />
<p><a href="javascript:jQuery('#uploadify').uploadifyClearQueue()">Cancel All Uploads</a></p>
</div>
</body>
uploadify.php
<?php
//session_start();
include 'config.php';
$clientid = 1;
$timestamp = date('d/m/y g:i:s a', time());
$timestamp_day = substr($timestamp, 0, 2);
$timestamp_month = substr($timestamp, 3, 2);
$timestamp_year = substr($timestamp, 6, 2);
$filename = $clientid . '_' . $timestamp_day . $timestamp_month . $timestamp_year;
//GET AGENT - USERID
$userid = "";
$result = mysql_query("SELECT a.id FROM user a, client b WHERE b.heid = a.id AND b.id = '$clientid'");
while($row = mysql_fetch_assoc($result)){
$userid = $userid . $row['id'];
}
?>
<label>
<input type="hidden" name="userid" id="userid" value="<?php echo $userid; ?>" />
<input type="hidden" name="filename" id="filename" value="<?php echo $filename; ?>" />
</label>
<?
$result2 = mysql_query ("select filename from photo WHERE filename like '%$filename%'");
$row2 = mysql_fetch_array($result2);
if($filename==$row2['filename'])
{
echo '<script language="javascript">alert(\'Album is already exist.\');</script>';
include('class.upload.php');
//GET TIMESTAMP from database
$timestamp = "";
$result1 = mysql_query("SELECT timestamp FROM photo WHERE clientid = '$clientid' AND filename = '$filename'");
while($row1 = mysql_fetch_assoc($result1)){
$timestamp = $timestamp . $row1['timestamp'];
}
$timestamp_day = substr($timestamp, 0, 2);
$timestamp_month = substr($timestamp, 3, 2);
$year = substr($timestamp, 6, 2);
$twenty = 20;
$timestamp_year = $twenty . $year;
?>
<form action="" method="POST">
<input type="hidden" name="clientid" value="<?php echo $clientid; ?>">
<input type="hidden" name="filename" value="<?php echo $filename; ?>">
</form>
<?
/*
Uploadify v2.1.0
Release Date: August 24, 2009
Copyright (c) 2009 Ronnie Garcia, Travis Nickels
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
//this is part of class.upload:
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = utf8_decode(str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']);
$file_id = md5($_FILES["Filedata"]["tmp_name"] + rand()*100000 + time());
$handle = new Upload($_FILES['Filedata']);
if ($handle->uploaded) {
$handle->file_src_name_body = time().$file_id; // hard name
//$handle->file_overwrite = true;
//$handle->file_auto_rename = false;
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_x = 600; //size of picture
$handle->file_max_size = '512000'; // max size
$handle->Process($targetPath.'/'.$timestamp_year.'/'.$timestamp_month.'/'.$filename.'/'.'full/');
// $handle-> Clean();
//thumbnail creation:
$handle->file_src_name_body = time().$file_id; // hard name
//$handle->file_overwrite = true;
//$handle->file_auto_rename = false;
$handle->image_resize = true;
//$handle->image_ratio_y = true;
$handle->image_ratio_x = true;
$handle->image_y = 70; //size of picture
$handle->file_max_size = '512000'; // max size
$handle->Process($targetPath.'/'.$timestamp_year.'/'.$timestamp_month.'/'.$filename.'/'.'thumbs/');
$handle-> Clean();
echo "1";
} else {
}
}
}
else
{
//INSERT new album in database
mysql_query ("INSERT INTO photo(userid, clientid, filename, timestamp)
values ('$userid','$clientid','$filename','$timestamp')") or die(mysql_error());
include('class.upload.php');
//GET TIMESTAMP from database
$timestamp = "";
$result1 = mysql_query("SELECT timestamp FROM photo WHERE clientid = '$clientid' AND filename = '$filename'");
while($row1 = mysql_fetch_assoc($result1)){
$timestamp = $timestamp . $row1['timestamp'];
}
$timestamp_day = substr($timestamp, 0, 2);
$timestamp_month = substr($timestamp, 3, 2);
$year = substr($timestamp, 6, 2);
$twenty = 20;
$timestamp_year = $twenty . $year;
?>
<form action="" method="POST">
<input type="hidden" name="clientid" value="<?php echo $clientid; ?>">
<input type="hidden" name="filename" value="<?php echo $filename; ?>">
</form>
<?
//this is part of class.upload:
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = utf8_decode(str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']);
$file_id = md5($_FILES["Filedata"]["tmp_name"] + rand()*100000 + time());
$handle = new Upload($_FILES['Filedata']);
if ($handle->uploaded) {
$handle->file_src_name_body = time().$file_id; // hard name
//$handle->file_overwrite = true;
//$handle->file_auto_rename = false;
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_x = 600; //size of picture
$handle->file_max_size = '512000'; // max size
$handle->Process($targetPath.'/'.$timestamp_year.'/'.$timestamp_month.'/'.$filename.'/'.'full/');
// $handle-> Clean();
//thumbnail creation:
$handle->file_src_name_body = time().$file_id; // hard name
//$handle->file_overwrite = true;
//$handle->file_auto_rename = false;
$handle->image_resize = true;
//$handle->image_ratio_y = true;
$handle->image_ratio_x = true;
$handle->image_y = 70; //size of picture
$handle->file_max_size = '512000'; // max size
$handle->Process($targetPath.'/'.$timestamp_year.'/'.$timestamp_month.'/'.$filename.'/'.'thumbs/');
$handle-> Clean();
echo "1";
} else {
}
}
}
?>