Hi,
I have just downloaded uploadify and have run a few tests to see if it works straight away on my server which it does.
this is the tutorial i found for implementing but it is not clear at all: uploadify tutorial. i want to be able to use my own script to resize, rename and then move it to it's proper location
this is the upload code that it uses
and this is what i want to change it to
I have just downloaded uploadify and have run a few tests to see if it works straight away on my server which it does.
this is the tutorial i found for implementing but it is not clear at all: uploadify tutorial. i want to be able to use my own script to resize, rename and then move it to it's proper location
this is the upload code that it uses
Code:
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
// $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);
echo "1";
// } else {
// echo 'Invalid file type.';
// }
}
Code:
<? session_start();
include ("admin-dbcon.php");
$userName = $_SESSION['_amember_user']['login'];
$firstName = $_SESSION['_amember_user']['name_f'];
$firstName = ucfirst($firstName);
$lastName = $_SESSION['_amember_user']['name_l'];
$lastName = ucfirst($lastName);
$random_digit = $_POST['ID'];
$returnURL = $_POST['returnURL'];
$thumbTemp=mkdir("uploads/tmp/$userName/t/", 0777);
$mainTemp=mkdir("uploads/tmp/$userName/m/", 0777);
$albumName = $_POST['albumName'];
include('SimpleImage.php');
while(list($key,$value) = each($_FILES['file']['name']))
{
if(!empty($value))
{
$filename = $value;
$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
$add = "uploads/tmp/$userName/m/$filename";
$tempFLDR = "uploads/tmp/$userName/t/$filename";
//echo $_FILES['images']['type'][$key];
// echo "<br>";
copy($_FILES['file']['tmp_name'][$key], $add);
chmod("$add",0777);
copy($_FILES['file']['tmp_name'][$key], $tempFLDR);
chmod("$tempFLDR",0777);
$folderPath="upload/$random_digit/";
}
$imgSize = getimagesize($add);
echo $details[0].'<br/>';
echo $details[1].'<br/>';
if ($imgSize[0] > $imgSize[1]){
$image = new SimpleImage();
$image->load("$add");
$image->resize(450,350);
$image->save("$add");
$image = new SimpleImage();
$image->load("$tempFLDR");
$image->resize(100,100);
$image->save("$tempFLDR");
}
elseif ($imgSize[1] > $imgSize[0]) {
$image = new SimpleImage();
$image->load("$add");
$image->resize(240,350);
$image->save("$add");
$image = new SimpleImage();
$image->load("$tempFLDR");
$image->resize(100,100);
$image->save("$tempFLDR");
}
}
mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
// Select column 1 from table name where column name = $your_var.
// If mysql_query returns false, we'll die with the error.
$result = mysql_query("SELECT * FROM imgUpload WHERE tempID = {$random_digit}");
// If a there is a match
if ( mysql_num_rows( $result ) > 0 )
{
$row = mysql_fetch_array( $result );
//fill in details about the path
$path="uploads/tmp/$userName/m/";
$pathA="uploads/$userName/$albumName/";
//variable used for the name of each file
$i=$row['lastDigit'];
$od = opendir($path);
while (false !== ($filename = readdir($od)))
{
//you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
if($filename != '.' && $filename != '..' && !is_dir($path.$filename))
{
//we give files a name - here we use increasing numbers for jpg files:
if(rename($path.$filename, $pathA.$i++.'.jpg'))
echo '<br />';
}
}
closedir($od);
//fill in details about the path
$pathT="uploads/tmp/$userName/t/";
$pathF="uploads/$userName/$albumName/";
//variable used for the name of each file
$i=$row['lastDigit'];
$odT = opendir($pathT);
while (false !== ($filename = readdir($odT)))
{
//you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
if($filename != '.' && $filename != '..' && !is_dir($pathT.$filename))
{
//we give files a name - here we use increasing numbers for jpg files:
if(rename($pathT.$filename, $pathF.$i++.'b.jpg'))
echo '<br />';
}
}
closedir($odT);
$query="
UPDATE imgUpload SET
lastDigit='{$i}'
WHERE tempID= '{$random_digit}' ";
}
else
{
//fill in details about the path
$path="uploads/tmp/$userName/m/";
$pathA="uploads/$userName/$albumName/";
//variable used for the name of each file
$nw=1;
$od = opendir($path);
while (false !== ($filename = readdir($od)))
{
//you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
if($filename != '.' && $filename != '..' && !is_dir($path.$filename))
{
//we give files a name - here we use increasing numbers for jpg files:
if(rename($path.$filename, $pathA.$nw++.'.jpg'))
echo '<br />';
}
}
closedir($od);
//fill in details about the path
$pathT="uploads/tmp/$userName/t/";
$pathF="uploads/$userName/$albumName/";
//variable used for the name of each file
$nw=1;
$odT = opendir($pathT);
while (false !== ($filename = readdir($odT)))
{
//you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
if($filename != '.' && $filename != '..' && !is_dir($pathT.$filename))
{
//we give files a name - here we use increasing numbers for jpg files:
if(rename($pathT.$filename, $pathF.$nw++.'b.jpg'))
echo '<br />';
}
}
closedir($odT);
$query="INSERT imgUpload (tempID,lastDigit)
VALUES(
'$random_digit',
'$nw')";
}
$result=mysql_query($query) or die("Error in query:".mysql_error());
mysql_close();
$rmA = "uploads/tmp/$userName/t/";
$rmB = "uploads/tmp/$userName/m/";
$mydirA = "$rmA";
$d = dir($mydirA);
while($entry = $d->read()) {
if ($entry!= "." && $entry!= "..") {
unlink($entry);
}
}
$d->close();
rmdir($mydirA);
$mydirB = "$rmB";
$d = dir($mydirB);
while($entry = $d->read()) {
if ($entry!= "." && $entry!= "..") {
unlink($entry);
}
}
$d->close();
rmdir($mydirB);
?>
<script language="JavaScript">
<!--
window.location="<? print $returnURL?>";
//-->
</SCRIPT>
</body>
</html>
Comment