Jump to content

passing variable to PHP page


woodplease

Recommended Posts

i'm using swfupload to upload multiple files to a server. when the JavaScript runs, it calls the upload script on a separate php file. ive set the variable that defines what php file to load so that it passes a $_GET variable in the URL

upload_url: "upload-file.php?album_id=<?php echo $album_id; ?>",

This so on the actual upload page, i can add this variable to the database, along with detail about the uploaded file. My problem is that i'm not sure if the page is retrieving the variable as the page itself is never actually displayed. I've added an sql script to it to add to the database, but nothing gets added.

 

First page

<script type="text/javascript">
$(function(){
$('#swfupload-control').swfupload({
	upload_url: "upload-file.php?album_id=<?php echo $album_id; ?>",
	file_post_name: 'uploadfile',
	file_size_limit : "10240",
	file_types : "*.jpg;*.png;*.gif",
	file_types_description : "Image files",
	file_upload_limit : 20,
	flash_url : "js/swfupload/swfupload.swf",
	button_image_url : 'js/swfupload/wdp_buttons_upload_114x29.png',
	button_width : 114,
	button_height : 29,
	button_placeholder : $('#button')[0],
	debug: false
})
	.bind('fileQueued', function(event, file){
		var listitem='<li id="'+file.id+'" >'+
			'File: <em>'+file.name+'</em> ('+Math.round(file.size/1024)+' KB) <span class="progressvalue" ></span>'+
			'<div class="progressbar" ><div class="progress" ></div></div>'+
			'<p class="status" >Pending</p>'+
			'<span class="cancel" > </span>'+
			'</li>';
		$('#log').append(listitem);
		$('li#'+file.id+' .cancel').bind('click', function(){
			var swfu = $.swfupload.getInstance('#swfupload-control');
			swfu.cancelUpload(file.id);
			$('li#'+file.id).slideUp('fast');
		});
		// start the upload since it's queued
		$(this).swfupload('startUpload');
	})
	.bind('fileQueueError', function(event, file, errorCode, message){
		alert('Size of the file '+file.name+' is greater than limit');
	})
	.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
		$('#queuestatus').text('Files Selected: '+numFilesSelected+' / Queued Files: '+numFilesQueued);
	})
	.bind('uploadStart', function(event, file){
		$('#log li#'+file.id).find('p.status').text('Uploading...');
		$('#log li#'+file.id).find('span.progressvalue').text('0%');
		$('#log li#'+file.id).find('span.cancel').hide();
	})
	.bind('uploadProgress', function(event, file, bytesLoaded){
		//Show Progress
		var percentage=Math.round((bytesLoaded/file.size)*100);
		$('#log li#'+file.id).find('div.progress').css('width', percentage+'%');
		$('#log li#'+file.id).find('span.progressvalue').text(percentage+'%');
	})
	.bind('uploadSuccess', function(event, file, serverData){
		var item=$('#log li#'+file.id);
		item.find('div.progress').css('width', '100%');
		item.find('span.progressvalue').text('100%');
		var pathtofile='<a href="uploads/'+file.name+'" target="_blank" ></a>';
		item.addClass('success').find('p.status').html('Done!!!  '+pathtofile);
	})
	.bind('uploadComplete', function(event, file){
		// upload has completed, try the next one in the queue
		$(this).swfupload('startUpload');
	})

});	

</script>

 

Upload-file.php

<?php
include "dbconnect.php";
if (isset($_GET['album_id'])){
$album_id = $_GET['album_id'];
}
$time = time();
$uploaddir = './images/album_photos/'; 
$name = mt_rand(). basename($_FILES['uploadfile']['name']);
$file = $uploaddir.$name; 
$size=$_FILES['uploadfile']['size'];
if($size>10485760)
{
echo "error file size > 10 MB";
unlink($_FILES['uploadfile']['tmp_name']);
exit;
}
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { 
  echo "success"; 
} else {
echo "error ".$_FILES['uploadfile']['error']." --- ".$_FILES['uploadfile']['tmp_name']." %%% ".$file."($size)";
}
?>
<?php
$img = imagecreatefromjpeg($file);
	    $width = imagesx($img);
	    $height = imagesy($img);
		$thumbWidth = 100;
	    $new_width = $thumbWidth;
	    $new_height = floor($height * ($thumbWidth / $width));
	    $tmp_img = imagecreatetruecolor($new_width, $new_height);
	    imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
	    imagejpeg($tmp_img, "images/photo_thumbs/t_".$name);
      	    imagedestroy($tmp_img);
	    imagedestroy($img);
$thumb_url = "images/photo_thumbs/t_".$name;	

$img = imagecreatefromjpeg($file);
	    $width = imagesx($img);
	    $height = imagesy($img);
		if ($height > $width){
			$thumbHeight = 500;
			$new_height = $thumbHeight;			
			$new_width = floor($width * ($thumbHeight / $height));
		} else {			
			$thumbWidth = 500;
			$new_width = $thumbWidth;
			$new_height = floor($height * ($thumbWidth / $width));
		}
	    $tmp_img = imagecreatetruecolor($new_width, $new_height);
	    imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
	    imagejpeg($tmp_img, "images/display_photos/d_".$name);
      	    imagedestroy($tmp_img);
	    imagedestroy($img);
$display_url = "images/display_photos/d_".$name;	

mysql_query("INSERT INTO photos (upload_date, url, display_url, thumb_url, album_id) VALUES ('".$time."', '".$file."', '".$display_url."','".$thumb_url."', '".$album_id."')") or die (mysql_error());

?>

 

Any ideas?

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.