Ok, I'm really lost here. I tried everything, but it doesn't seem to work. I'm using an upload script (uploadify) and I want to enter the username with the name of the image in the database. But for some reason the username is always blank. Here is my code: PHP: <?phpsession_start();//Error logginginclude("../logger.php");$handler = new Logger(LOGGER_ALL, METHOD_LOG);set_error_handler(array($handler, "Handle"));//Watermark classrequire_once 'phpgdwatermarker.php';/*Uploadify v2.1.1Release Date: November 1, 2010Copyright (c) 2010 Ronnie Garcia, Travis NickelsPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, 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 INTHE SOFTWARE.*/if (!empty($_FILES)) {$random=rand(0000000000,9999999999);$newName = $random.$_FILES['Filedata']['name'];$user = $_SESSION['_amember_login']; $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; $targetFile = str_replace('//','/',$targetPath) . $newName; // $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 if(!file_exists($targetPath) && !file_exists("../../thumbs") && !file_exists("../../small")){ mkdir(str_replace('//','/',$targetPath), 0755, true); mkdir(str_replace('//','/',"../../thumbs"), 0755, true); mkdir(str_replace('//','/',"../../small"), 0755, true); } //Get image size $size = getimagesize($tempFile); if($size[0] < 150 || $size[1] < 150) { echo "0"; exit; } //Change the size of the original image $large = '../../gallery/'.$newName; $file = $_FILES['Filedata']['tmp_name']; $size = 0.25; list($width, $height) = getimagesize($file) ; if($width > 2000 || $height > 2000){ $modwidth = $width * $size; $modheight = $height * $size; }else if($width > 1000 || $height > 1000){ $modwidth = $width * 0.5; $modheight = $height * 0.5; }else{ $modwidth = $width; $modheight = $height; } $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; // Save the JPEG to the folder specified imagejpeg($tn, $large, 100) ; //Include resizer include ("resize.php"); //Add watermark to images $watermarker = new PhpGdWatermarker('../watermarks/watermark.png'); if($watermarker->applyWaterMark($targetPath.$newName)){ echo ""; } else { echo $watermarker->getLastErrorMessage(); } echo $newName; //Start new connection /*** mysql hostname ***/ $hostname = 'localhost'; /*** mysql username ***/ $username = 'username'; /*** mysql password ***/ $password = 'password'; try { $dbh = new PDO("mysql:host=$hostname;dbname=database", $username, $password); /*** set the error reporting attribute ***/ $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING ); //Check filename for specialchars $newName = htmlspecialchars($newName, ENT_QUOTES); /*** prepare the SQL statement ***/ $stmt = $dbh->prepare("INSERT INTO gallery (username, filename) VALUES (:username, :name)"); $stmt->bindParam(':username', $user); $stmt->bindParam(':name', $newName); /*** execute the prepared statement ***/ $stmt->execute(); /*** close the database connection ***/ $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } }?> I have checked all the scripts I'm including for DESTROY SESSION or if a session is opened, but I can't find anything. I also changed the variable for the login session to different names, but without any luck. I'ts already 2 hours now that I'm trying to solve this, but I just can't figure out what I'm doing wrong. Thanks in advance for any help. mw
Ok I solved it by posting the username to the upload page. But it's still weird I can't use SESSION in the upload page.
Here is what you need to check: 1. Make sure that domain name in urls for aMember and this script are the same (www.domain.com and domain.com are different domains) 2. Check session settings in aMember CP -> Version Info then create info.php with this code: <?php phpinfo(); ?> inside the folder where you have that uploader script and make sure that settings are the same exactly.
Hi Alexander, Thanks for your answer. I did what you asked. I'm still working on localhost, so I skipped tip number 1. For the second one they are the same, but the problem still exists. The session variable disappears every time I try to use it. Instead I have to post it as hidden field to the next document if I want to use it. Here is another example: PHP: // Set the path to the image to watermark $input_image = $targetPath.$newName; // Read in the text watermark image $myName = $_SESSION['_amember_login']; $watermark = imagecreatefrompng("../watermarks/{$myName}.png"); // Returns the width of the given image resource $watermark_width = imagesx( $watermark ); //Returns the height of the given image resource $watermark_height = imagesy( $watermark ); $image = imagecreatetruecolor( $watermark_width, $watermark_height ); $image = imagecreatefromjpeg( $input_image ); // Find the size of the original image and read it into an array $size = getimagesize( $input_image ); // Set the positions of the watermark on the image $differenceX = $size[0] - $watermark_width; $differenceY = $size[1] - $watermark_height; $dest_x = round($differenceX / 2); $dest_y = round($differenceY / 2); imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 40); // Save the watermarked image as watermarked.jpg imagejpeg( $image, "watermarked.jpg" ); // Clear the memory of the tempory image imagedestroy( $image ); imagedestroy( $watermark ); No matter what I do, I can't get it to point to "..watermarks/moonwalker.png" If I use a hidden posted variable, it works fine. Thanks.