Jump to content

Image uploader


andyd34

Recommended Posts

Can someone please have a look at the following and let me know where i am going wrong as each time i click on an image in the dialog box it attemps to upload then gives an error

 

upload html page



$(document).ready( function(){
$("#load_images").load("./ajax/load_images.php");

var btnUpload=$('#upload');
var status=$('#status');
new AjaxUpload(btnUpload, {
	action: 'uploader.php',
	name: 'uploadfile',
	onSubmit: function(file, ext)
	{
		 if (! (ext && /^(jpg|jpeg)$/.test(ext)))
		 { 
			status.text('Only JPG files are allowed');
			return false;
		 }
		status.html('<img src="./images/icons/indicator.gif" />');
	},
	onComplete: function(file, response)
	{
		//On completion clear the status
		status.text('');
		status.html('');
		//Add uploaded file to list
		if(response==="success"){
			$("#load_images").load("./ajax/load_images.php");
		} else{
			$('<li></li>').appendTo('#files').text("error uploading "+file).addClass('error');
		}
	}
});
});

 

uploader file

<?
/**
*
* @package phpBB3
* @version $Id: index.php 8987 2008-10-09 14:17:02Z acydburn $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);


// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

$uploaddir = './images/img_uploads/'; 
$filename = $_FILES['uploadfile']['tmp_name']; 
//$fname = $_FILES['uploadfile']['name'];
$fname = time().".jpg";
$image = imagecreatefromjpeg($filename);  
list($width,$height)=getimagesize($filename);




if($width>='400') {
$newwidth=400;
$newheight=($height/$width)*$newwidth;
}
else
{
$newwidth=200;
$newheight=($height/$width)*$newwidth;
}
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$image,0,0,0,0,$newwidth,$newheight,$width,$height);

$font_size = '12px';
$color = imagecolorallocate($tmp, 255,255,255);
$text = "{SITENAME}: " . $user->data['username'] . "";
$font = "arial.ttf";
$bottom = $newheight - 20;
imagettftext ($tmp, $font_size, 0, 10, $bottom, $color, $font, $text); 
imagettftext ($tmp, $font_size, 0, 10, 20, $color, $font, $text); 

$file = $uploaddir . $fname; 

if (imagejpeg($tmp, $file)) { 
$img_date = time();
mysql_query("INSERT INTO phpbb_img_uploads (file_name, file_loaded, file_status, user_id) VALUES ('$fname', '$img_date', 'private', '" . $user->data['username'] . "')");
  echo "success"; 
imagedestroy($tmp); 
imagedestroy($image);  
} else {
imagedestroy($tmp); 
imagedestroy($image);  
}
?>

 

and not forgetting the head tags


<script language="javascript" type="text/javascript" src="./js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="./js/jquery.form.js"></script>
<script language="javascript" type="text/javascript" src="./js/ajaxupload.js"></script>
<script language="javascript" type="text/javascript" src="./js/jquery.cycle.js"></script>
<script language="javascript" type="text/javascript" src="./js/jquery.lightbox.js"></script>
<script language="javascript" type="text/javascript" src="./js/jquery.MultiFile.js"></script>
<script language="javascript" type="text/javascript" src="./js/jquery.selectCombo.js"></script>
<script language="javascript" type="text/javascript" src="./js/jquery.maskedinput.js"></script>

 

The error is not a coding error rather the generated error when a file could not be uploaded but its doing it on every .jpg image file i try to upload.

 

The directory files and folders are correct, i just cant get my head round where i have gone wrong

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.