Rank: Member
Groups: Member
Joined: 12/16/2006(UTC) Posts: 3
|
^^ Thanks, after looking in the script file, I figured that out as well. One other question though, not really related to this thread, but its something I am coming across. I am trying to do database inserts within the for loop in upload.php to keep track of each individual photo. I am having problems getting it to work, and I cannot seem to figure out why. Just to make sure I am not being dumb here, there should be no problems with the upload.php page performing a $_GET['x'] and reading a cookie ($_COOKIE['ID']) as part of the script, right? I tested my implementation with the xml, and it worked fine, and then when I tested with the mysql script, it didnt save any photos to the folder, nor did it insert anything into the database... In this code, I am trying to save the image and the thumbnail into the same directory, which is based on a users ID and the Album ID ... the thumbnail is just named t-file.jpg to differentiate the two. Code:<?php require_once('../Connections/file.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
//if(isset($_COOKIE['UserID'])){
//$thisUser = $_COOKIE['UserID'];
$colname_rsPermit = "-1";
if (isset($_GET['AID'])) {
$colname_rsPermit = (get_magic_quotes_gpc()) ? $_GET['AID'] : addslashes($_GET['AID']);
}else header("Location: ../index.html");
mysql_select_db($database_famijam, $famijam);
$query_rsPermit = sprintf("SELECT * FROM ualbum WHERE intUAlbumID = %s", $colname_rsPermit);
$rsPermit = mysql_query($query_rsPermit, $famijam) or die(mysql_error());
$row_rsPermit = mysql_fetch_assoc($rsPermit);
$totalRows_rsPermit = mysql_num_rows($rsPermit);
$thisUser = $row_rsPermit['intUserID'];
//if($totalRows_rsPermit>1){
//This variable specifies relative path to the folder, where the gallery with uploaded files is located.
//Do not forget about the slash in the end of the folder name.
$galleryPath = "users/".$thisUser."/".$_GET['AID']."/";
$absGalleryPath = realpath($galleryPath) . "/";
$absThumbnailsPath = realpath($galleryPath) . "/";
function saveUploadedFiles()
{
global $absGalleryPath, $absThumbnailsPath, $thisUser;
//First of all, clear files and data uploaded at previous time.
//Delete source files.
//$handle = opendir($absGalleryPath);
//while (false !== ($file = readdir($handle)))
//{
// if (is_file($absGalleryPath . $file))
// {
// unlink($absGalleryPath . $file);
// }
//}
//closedir($handle);
//Delete thumbnails
//$handle = opendir($absThumbnailsPath);
//while (false !== ($file = readdir($handle)))
//{
// if (is_file($absThumbnailsPath . $file))
// {
// unlink($absThumbnailsPath . $file);
// }
//}
//closedir($handle);
//NOTE: If you do not want to delete previously uploaded files, just
//remove or comment out the code above.
//Create XML file which will keep information about files (image dimensions, description, etc).
//XML is used solely for brevity. In real-life application most likely you will use database instead.
//$descriptions = new DOMDocument('1.0');
//$descriptions->appendChild($descriptions->createElement("files"));
//Get total number of uploaded files (all files are uploaded in a single package).
$fileCount = $_POST ["FileCount"];
//Iterate through uploaded data and save the original file, thumbnail, and description.
for ($i = 1; $i <= $fileCount; $i++)
{
//Get the first thumbnail and save it to disk. It stores 640x480 optimized image.
$thumbnail1Field = "Thumbnail1_" . $i;
if (!$_FILES[$thumbnail1Field]['size'])
{
return;
}
$fileName = getSafeFileName(basename($_POST["FileName_" . $i]));
move_uploaded_file($_FILES[$thumbnail1Field]['tmp_name'], $absGalleryPath . "/" . $fileName);
//$totalUploadedFileSize = $totalUploadedFileSize + filesize($absGalleryPath . "/" . $fileName);
//Get the second thumbnail and save it to disk. It stores 88x66 preview image.
$thumbnail2Field = "Thumbnail2_" . $i;
if (!$_FILES[$thumbnail2Field]['size'])
{
return;
}
move_uploaded_file($_FILES[$thumbnail2Field]['tmp_name'], $absGalleryPath . "/t-" . $fileName);
// Insert Pic info into database
$insertSQL = sprintf("INSERT INTO upics (upicName, upicTitle, upicDesc, intUserID, upitWidth, upicHeight, intUAlbumID) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($fileName, "text"),
GetSQLValueString($_POST ['Title_' . $i], "text"),
GetSQLValueString($_POST ['Description_' . $i], "text"),
GetSQLValueString($thisUser, "int"),
GetSQLValueString($_POST ['Width_' . $i], "int"),
GetSQLValueString($_POST ['Height_' . $i], "int"),
GetSQLValueString($_GET['AID'], "int"));
mysql_select_db($database_famijam, $famijam);
$Result1 = mysql_query($insertSQL, $famijam) or die(mysql_error());
//Get first thumbnail (the single thumbnail in this code sample) and save it to disk.
//$thumbnail1Field = "Thumbnail1_" . $i;
//if (!$_FILES[$thumbnail1Field]['size'])
//{
// return;
//}
//move_uploaded_file($_FILES[$thumbnail1Field]['tmp_name'], $absGalleryPath . "/Thumbnails/" . $fileName . ".jpg");
//Save file info.
//$xmlFile = $descriptions->createElement("file");
//$xmlFile->setAttribute("name", $fileName);
//$xmlFile->setAttribute("width", $_POST ['Width_' . $i]);
//$xmlFile->setAttribute("height", $_POST ['Height_' . $i]);
//$xmlFile->setAttribute("title", $_POST ['Title_' . $i]);
//$xmlFile->setAttribute("description", $_POST ['Description_' . $i]);
//$descriptions->documentElement->appendChild($xmlFile);
}
//$descriptions->save($absGalleryPath . "Descriptions.xml");
}
//This method verifies whether file with such name already exists
//and if so, construct safe filename name (to avoid collision).
function getSafeFileName($fileName)
{
global $absGalleryPath;
$newFileName = $fileName;
$j = 1;
while (file_exists($absGalleryPath . "/" . $newFileName))
{
$newFileName = $j . "_" . $fileName;
$j = $j + 1;
}
return $newFileName;
}
saveUploadedFiles();
// }
mysql_free_result($rsPermit);
//}
?>
If you could help me track down the problem, I would appreciate it... Edited by user Tuesday, December 18, 2007 7:40:07 PM(UTC)
| Reason: Not specified |
Rob <a href="http://www.GoOffCampus.com">Student Housing</a> | <a href="http://www.manageyourlinks.com">SEO Link Management</a> | <a href="http://www.famijam.com">Family Photo Sharing</a>
|