Hi everyone. I’m new to this site. I’m here to ask your experts what is wrong with my codes, or what needs to be change. It is said that the picture was successful loaded but at the same time I got this error message. Warning: getimagesize(pics//home/hmonglis/public_html/nkaujhmoob/pics/50-o.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home1/username/public_html/nkaujhmoob/upload.php on line 186.
Here’s the upload codes:
[php]<?php
include(“include/config.php”);
include(“include/functions/import.php”);
require(“include/functions/ImageTools.class.php”);
//$UID = intval(cleanit($_SESSION[‘USERID’]));
intval(cleanit($_SESSION[‘USERID’])) ? $UID = intval(cleanit($_SESSION[‘USERID’])) : $UID = 1234567890;
if ($UID > 0)
{
if($_REQUEST[‘sub’]!="")
{
$caption = cleanit($_REQUEST[‘caption’]);
$category = intval(cleanit($_REQUEST[‘category’]));
$uploadedimage = $_FILES[‘selectphoto’][‘tmp_name’];
if($uploadedimage == “”) $errors[] = $lang[‘43’];
function check_email_address($email) {
// First, we check that there's one @ symbol,
// and that the lengths are right.
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters
// in one section or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if
(!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
↪'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
$local_array[$i])) {
return false;
}
}
// Check if domain is IP. If not,
// it should be valid domain name
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if
(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
↪([A-Za-z0-9]+))$",
$domain_array[$i])) {
return false;
}
}
}
return true;
}
function genRandomString() {
$length = 15;
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = "";
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
foreach($_POST AS $key=>$value){
Stemplate::assign($key,$value);
if(empty($value)){
switch($key){
case "name": $errors[] = "Error: Please enter your name";
break;
case "address": $errors[] = "Error: Please enter your address";
break;
case "phone": $errors[] = "Error: Please enter your phone number";
break;
case "email": $errors[] = "Error: Please enter your email";
break;
}
}else{
if($key == "email" & !check_email_address($value)) $errors[] = "Error: Please enter a valid email address";
if($key == "name" & !preg_match('/^[a-z-\s]+$/i',$value)) $errors[] = "Error: Please enter a valid name";
if($key == "phone" & !preg_match('/^[0-9\--]+$/i',$value)) $errors[] = "Error: Please enter a valid phone number";
}
}
if(array_search("agreement",$_POST) == false) $errors[] = "Error: You must agree to our terms of use";
if(count($errors) > 0)
{
$error = implode("<br>",$errors);
}
else
{
$db = new MySQLi($DBHOST,$DBUSER,$DBPASSWORD,$DBNAME);
$sql = $db->query("SELECT value FROM config WHERE setting = 'watermark'");
$info = $sql->fetch_object();
define( 'WATERMARK_OVERLAY_IMAGE', $info->value );
define( 'WATERMARK_OVERLAY_OPACITY', 50 );
define( 'WATERMARK_OUTPUT_QUALITY', 90 );
function create_watermark( $source_file_path, $output_file_path )
{
list( $source_width, $source_height, $source_type ) = getimagesize( $source_file_path );
if ( $source_type === NULL )
{
return false;
}
switch ( $source_type )
{
case IMAGETYPE_GIF:
$source_gd_image = imagecreatefromgif( $source_file_path );
break;
case IMAGETYPE_JPEG:
$source_gd_image = imagecreatefromjpeg( $source_file_path );
break;
case IMAGETYPE_PNG:
$source_gd_image = imagecreatefrompng( $source_file_path );
break;
default:
return false;
}
$overlay_gd_image = imagecreatefrompng( WATERMARK_OVERLAY_IMAGE );
$overlay_width = imagesx( $overlay_gd_image );
$overlay_height = imagesy( $overlay_gd_image );
imagecopymerge(
$source_gd_image,
$overlay_gd_image,
$source_width - $overlay_width,
$source_height - $overlay_height,
0,
0,
$overlay_width,
$overlay_height,
WATERMARK_OVERLAY_OPACITY
);
imagejpeg( $source_gd_image, $output_file_path, WATERMARK_OUTPUT_QUALITY );
imagedestroy( $source_gd_image );
imagedestroy( $overlay_gd_image );
}
function process_image_upload( $filename )
{
$temp_file_path = "pics/$filename";
$temp_file_name = "pics/" . end(explode("/",$temp_file_path));
$processed_file_path = "pics/" . end(explode("/",$temp_file_path));
list( $temp_type ) = getimagesize( $temp_file_path );
if ( $temp_type === NULL )
{
return false;
}
switch ( $temp_type )
{
case IMAGETYPE_GIF:
break;
case IMAGETYPE_JPEG:
break;
case IMAGETYPE_PNG:
break;
default:
return false;
}
$result = create_watermark( $temp_file_name, $processed_file_path );
if ( $result === false )
{
return false;
}
else
{
return array( $temp_file_name, $processed_file_path );
}
}
$code = genRandomString();
$query="INSERT INTO posts SET USERID='".mysql_real_escape_string($UID)."', active='0', time_added='".time()."', date_added='".date("Y-m-d")."', caption='".mysql_real_escape_string($caption)."', category='".mysql_real_escape_string($category)."', name='".mysql_real_escape_string($_POST["name"])."' , email='".mysql_real_escape_string($_POST["email"])."' , phone='".mysql_real_escape_string($_POST["phone"])."' , address='".mysql_real_escape_string($_POST["address"])."' , comment='".mysql_real_escape_string($_POST["comment"])."' , code='".mysql_real_escape_string($code)."'";
$result=$conn->execute($query);
$id = mysql_insert_id();
$upload_file = $_FILES['selectphoto']['name'];
$pos = strrpos($upload_file,".");
$ph = strtolower(substr($upload_file,$pos+1,strlen($upload_file)-$pos));
$theimageinfo = getimagesize($uploadedimage);
$thepp = $id;
if($ph == "bmp")
{
$theppB .= $id."-o.bmp";
$thepp .= "-o.jpg";
$thepp2 = ".jpg";
}
elseif($theimageinfo[2] == 1)
{
$thepp .= "-o.gif";
$thepp2 = ".gif";
}
elseif($theimageinfo[2] == 2)
{
$thepp .= "-o.jpg";
$thepp2 = ".jpg";
}
elseif($theimageinfo[2] == 3)
{
$thepp .= "-o.png";
$thepp2 = ".png";
}
else
{
$error = $lang['44'];
}
if($error == "")
{
if($ph == "bmp")
{
$upbmpimage=$config['pdir']."/".$theppB;
if(file_exists($upbmpimage))
{
unlink($upbmpimage);
}
$myconvertimg = $_FILES['selectphoto']['tmp_name'];
move_uploaded_file($myconvertimg, $upbmpimage);
$myvideoimgnew=$config['pdir']."/".$thepp;
$img = ImageCreateFromBmp($upbmpimage);
imagejpeg($img, $myvideoimgnew);
myvideoimgnew($myvideoimgnew);
process_image_upload($myvideoimgnew);
}
else
{
$myvideoimgnew=$config['pdir']."/".$thepp;
if(file_exists($myvideoimgnew))
{
unlink($myvideoimgnew);
}
$myconvertimg = $_FILES['selectphoto']['tmp_name'];
move_uploaded_file($myconvertimg, $myvideoimgnew);
process_image_upload($myvideoimgnew);
}
$isan = is_animated_gif($myvideoimgnew);
if($isan > 0)
{
$newfile = $config['pdir']."/".$id.$thepp2;
copy($myvideoimgnew, $newfile);
}
else
{
$img = new ImageTools($myvideoimgnew);
$imw1 = $img->getX();
if($imw1 > 620)
{
$img->resizeWidth(620);
}
$img->save($config['pdir']."/", $id.$thepp2, "90", true);
process_image_upload($id.$thepp2);
}
$img = new ImageTools($myvideoimgnew);
$imw2 = $img->getX();
if($imw2 > 150)
{
$img->resizeNewByWidth(114, 114, 150, "#FFF");
}
elseif($imw2 > 0)
{
$img->resizeNewByWidth(114, 114, $imw2, "#FFF");
}
else
{
$img->resizeWidth(114);
$sd2 = "1";
}
$img->save($config['pdir']."/", $id."-t".$thepp2, "90", true);
//process_image_upload($id."-t".$thepp2);
if($sd2 != "1")
{
$img->destroy();
}
$img = new ImageTools($myvideoimgnew);
$imw3 = $img->getX();
if($imw3 > 150)
{
$img->resizeNewByWidth(84, 84, 150, "#FFF");
}
elseif($imw3 > 0)
{
$img->resizeNewByWidth(84, 84, $imw3, "#FFF");
}
else
{
$img->resizeWidth(84);
$sd3 = "1";
}
$img->save($config['pdir']."/", $id."-t2".$thepp2, "90", true);
//process_image_upload($id."-t2".$thepp2);
if($sd3 != "1")
{
$img->destroy();
}
if(file_exists($config['pdir']."/".$thepp))
{
process_image_upload($thepp);
if($config['approve_images'] == "0")
{
$active = ", active='1'";
$message = $lang['46'];
}
else
{
$message = $lang['47'];
}
$query = "UPDATE posts SET ext='$thepp2' $active WHERE PID='".mysql_real_escape_string($id)."'";
$conn->execute($query);
$mail_body = "<h3>Thanks for submitting your picture!</h3>";
$mail_body .= "You may click <a href='http://$_SERVER[HTTP_HOST]/upload?code=$code&id=$id'>here</a> if you wish to remove your picture from our servers.";
mail($_POST["email"],"Your Picture Submission!",$mail_body,"From: NkaujHmoob <[email protected]>\nContent-Type: text/html");
}
else
{
$error = $lang['45'];
}
}
}
}
}
/else
{
$r = base64_encode($config[‘baseurl’]."/upload");
header(“Location:$config[baseurl]/login?redirect=”.$r);exit;
}/
if(!$_GET){
$pagetitle = $lang['38'];
STemplate::assign('pagetitle',$pagetitle);
STemplate::assign('menu',"4");
STemplate::assign('message',$message);
STemplate::assign('error',$error);
STemplate::display('header.tpl');
STemplate::display('upload2.tpl');
STemplate::display('footer.tpl');
}elseif($_GET[“code”]){
$db = new MySQLi($DBHOST,$DBUSER,$DBPASSWORD,$DBNAME);
$query = “SELECT PID,ext FROM posts WHERE code = ‘$_GET[code]’ AND PID = ‘$_GET[id]’ LIMIT 1”;
$sql = $db->query($query);
$num = $sql->num_rows;
$info = $sql->fetch_object();
if($num > 0){
$query = "DELETE FROM posts WHERE code = '$_GET[code]' AND PID = '$_GET[id]' LIMIT 1";
$sql = $db->query($query);
$files = array("$info->PID$info->ext","$info->PID-t2$info->ext","$info->PID-t$info->ext","$info->PID-o$info->ext");
foreach($files AS $file) if(is_file($config['pdir'] . "/$file")) unlink($config['pdir'] . "/$file");
$message = "Your picture was succefully removed from our servers!";
}else $error = "We couldn't find a match for your query!";
$pagetitle = "Remove Picture";
STemplate::assign('pagetitle',$pagetitle);
STemplate::assign('menu',"4");
STemplate::assign('message',$message);
STemplate::assign('error',$error);
STemplate::display('header.tpl');
STemplate::display('delete_pic.tpl');
STemplate::display('footer.tpl');
}else{
$files = array("$info->PID.$info->ext","$info->PID-t2.$info->ext","$info->PID-t.$info->ext","$info->PID-o.$info->ext");
foreach($files AS $file) if(is_file($config['pdir'] . "/$file")) unlink($config['pdir'] . "/$file");
}
?>[/php][/code]