Sessions Variables
Posted: Sat May 23, 2009 10:39 pm
I can't get my sessions variables to work in a script I am working on:
The sessions variable contains the name of a file which I am trying to edit. When I put a static file name in $fp = fopen(myfile.xml, 'a+'); the script works just fine but when I try to feed my session variable in to this field, no file is being created. I have tried 'echo $dor' and the session variable seems to be successfully passed to the script. However this 'echo $dor' works only at the top of the file, if I place the same line near the bottom it no longer works. Any ideas what is going on here?!
Code: Select all
<?php
session_start(); // start up PHP session
$dor = $_SESSION['views'];
echo $dor;
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
$targetPath = str_replace('//','/',$targetPath);
$targetFile = $targetPath . $_FILES['Filedata']['name'];
move_uploaded_file($tempFile,$targetFile);
}
$imgsize = getimagesize($targetFile);
switch(strtolower(substr($targetFile, -3))){
case "jpg":
$image = imagecreatefromjpeg($targetFile);
break;
case "png":
$image = imagecreatefrompng($targetFile);
break;
case "gif":
$image = imagecreatefromgif($targetFile);
break;
default:
exit;
break;
}
$width = 80; //New width of image
$height = $imgsize[1]/$imgsize[0]*$width; //This maintains proportions
$src_w = $imgsize[0];
$src_h = $imgsize[1];
$picture = imagecreatetruecolor($width, $height);
imagealphablending($picture, false);
imagesavealpha($picture, true);
$bool = imagecopyresampled($picture, $image, 0, 0, 0, 0, $width, $height, $src_w, $src_h);
if($bool){
switch(strtolower(substr($targetFile, -3))){
case "jpg":
header("Content-Type: image/jpeg");
$bool2 = imagejpeg($picture,$targetPath."Thumbs/".$_FILES['Filedata']['name'],80);
break;
case "png":
header("Content-Type: image/png");
imagepng($picture,$targetPath."Thumbs/".$_FILES['Filedata']['name']);
break;
case "gif":
header("Content-Type: image/gif");
imagegif($picture,$targetPath."Thumbs/".$_FILES['Filedata']['name']);
break;
}
}
imagedestroy($picture);
imagedestroy($image);
echo '1'; // Important so upload will work on OSX
$dor = $_SESSION['views'];
$str = $_FILES['Filedata']['name'];
$fp = fopen($dor, 'a+');
fwrite($fp, $str);
fclose($fp);
echo '1';
?>