Hello,
I am getting crazy - I spent several hours trying to understand why my script is losing $nickname value, but no results. The third line of the script prints $nickname, but then just after "if ( count($_FILES) > 0 )" the value is lost - I am getting empty email - it doesn't contain $nickname. At the same time script is not losing $uploaddir and $thumbdir which are defined right after $nickname.
Please help.
======================================
<?php
@session_start();
$nickname=$_SESSION['g'];
echo "$nickname";
$uploaddir = dirname($_SERVER['SCRIPT_FILENAME'])."/pics/1test/";
$thumbdir = dirname($_SERVER['SCRIPT_FILENAME'])."/pics/1test/thumb/";
$thumbWidth = 120;
$thumbHeight = 120;
if ( count($_FILES) > 0 )
{
mail('my@mail.com', 'Nickname',$nickname);
foreach($_FILES as $fileName=>$file)
{
if ( $file['error'] != UPLOAD_ERR_OK )
{
header("HTTP/1.1 500 Internal Server Error");
switch( $file['error'] )
{
case UPLOAD_ERR_INI_SIZE:
echo "PHP Settings doesn't allow such file size";
break;
case UPLOAD_ERR_FORM_SIZE:
echo "Uploader didn't allow such file size";
break;
case UPLOAD_ERR_PARTIAL:
echo "Uploaded file hasn't been complete uploaded";
break;
case UPLOAD_ERR_NO_FILE:
echo "File hasn't been uploaded";
break;
}
break;
}
$fails=$file['name'];
$ext = substr($fails, (strrpos($fails,'.') + 1));
$ext = strtolower($ext);
$rand = rand(200,1999999999);
$failsj = "$vardi-$rand.$ext";
$uploadfile = "$uploaddir$failsj";
if ( move_uploaded_file( $file['tmp_name'], $uploadfile ) )
{
$ext = substr($uploadfile, strrpos($uploadfile,".") + 1 );
$image;
if( strcmp($ext, "jpeg") == 0 || strcmp($ext, "jpg") == 0 )
{
$image = imagecreatefromjpeg( $uploadfile );
}
elseif( strcmp($ext, "png") == 0 )
{
$image = imagecreatefrompng( $uploadfile );
}
elseif( strcmp($ext, "gif") == 0 )
{
$image = imagecreatefromgif( $uploadfile );
}
else
{
echo "This type of file doesn't supported";
return;
}
//scale operation
$thumbRatio = $thumbWidth/$thumbHeight;
$imageWidth = imagesx( $image );
$imageHeight = imagesy( $image );
$imageRatio = $imageWidth/$imageHeight;
if ( $thumbRatio < $imageRatio )
$thumbHeight = $thumbWidth/$imageRatio;
else
$thumbWidth = $thumbHeight*$imageRatio;
$thumbimage = imagecreatetruecolor((int)$thumbWidth, (int)$thumbHeight);
imagecopyresized($thumbimage, $image, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imageWidth, $imageHeight);
$thumbpath = "";
if( strcmp($ext, "jpeg") == 0 )
{
$thumbpath = $thumbdir.basename($uploadfile, ".jpeg");
}
elseif ( strcmp($ext, "jpg") == 0 )
{
$thumbpath = $thumbdir.basename($uploadfile, ".jpg");
}
elseif( strcmp($ext, "png") == 0 )
{
$thumbpath = $thumbdir.basename($uploadfile, ".png");
}
elseif( strcmp($ext, "gif") == 0 )
{
$thumbpath = $thumbdir.basename($uploadfile, ".gif");
}
$thumbpath = $thumbpath . "_thumb.gif";
imagegif( $thumbimage, $thumbpath);
header("HTTP/1.1 200 OK");
echo "thumbUrl=UploadedFiles/".basename($thumbpath);
}
else
{
header("HTTP/1.1 500 Internal Server Error");
echo "Can't move file from temporary directory to destination";
}
}
}
else
{
echo "Request didn't contain the file";
}
?>