Jump to content

Updated question on image uploads


nerdynewf

Recommended Posts

I have been working on changing my image gallery administration code to allow me to upload multiple files at once, but I think I must have something out of place. I can create and delete albums, change or delete photos I already have up there, but when I click on the option to add an image, nothing shows on the page ... no button to select files, or anything.

 

can someone please help?

 

Here is the edited bit of code to upload new images:

echo "<span class=\"adminHeader\">Image Gallery Administration</span><br /><br />";

IF ($do == "addImage") {

echo "<span class=\"actionHead\">Add an Image</span><br /><br />";

$page=$_GET['page'];
if(isset($_FILES['files'])){
    //$errors= array();
	foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
$descriptionPost = addslashes($_POST['description']);
$albumPost = addslashes($_POST['album']);
$image = $_FILES['theImage[]']['name'];

if($page=="submit"){$error = chkGalleryElements($image,$albumPost,$descriptionPost);}

	IF (($page=="submit")&&($error=="5")){

	$maxfilesize = 5000000;

	$query = "SELECT MAX(iid) FROM gallery";
	$result=mysql_query($query, $connection) or die("Query failed : " . mysql_error());
	$maxImageId = max(mysql_fetch_array($result)); 
	IF ($maxImageId==null){
	$maxImageId=0;
	}
	
	$imageName = $maxImageId + 1;

	$uploadfile = "$uploaddir$imageName.jpg";
	$uploadTHfile = $uploadTHdir."th_".$imageName.".jpg";
	$uploadsize = $_FILES['theImage']['size'];
						
	/*== get file extension (fn at bottom of script) ==*/
	/*== checks to see if image file, if not do not allow upload ==*/
	
	$pext = getFileExtension($image);
	$pext = strtolower($pext);
	if (($pext != "jpg")  && ($pext != "jpeg")) {
		print "<h1>ERROR</h1> The file you uploaded had the following extension: $pext.<br>";
		print "<p>Please upload an image with the extension .jpg or .jpeg ONLY.<br><br>";
		
		echo "<br /><br /><a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>";
		
	} elseif ($maxfilesize <= $uploadsize){
		echo "The image that you have uploaded is too big.  The system will accomodate any images up to 5MB and resize them to ensure optimal browsing.  If your file is larger than this, please resize the image.";
		echo "<br /><br /><a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>";
	} else {
		if (move_uploaded_file($_FILES['theImage']['tmp_name'], $uploadfile)) {
			
			// The file
			$filename = $uploadfile;
			$desiredwidth = 390;
			$desiredthumb_width = 150;
			
			// Get new dimensions
			list($width, $height) = getimagesize($filename);
			IF ($width > 390){
			$new_width = $desiredwidth;
			$new_height = $desiredwidth/$width * $height;
			}
			ELSE{
			$new_width = $width;
			$new_height = $height;
			}
			
			IF ($width > 150){
			$new_thumb_width = $desiredthumb_width;
			$new_thumb_height = $desiredthumb_width/$width * $height;
			}
			ELSE{
			$new_thumb_width = $width;
			$new_thumb_height = $height;
			}
			
			// Resample
			$image_p = imagecreatetruecolor($new_width, $new_height);
			$image = imagecreatefromjpeg($filename);
			imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
			
			$image_t = imagecreatetruecolor($new_thumb_width, $new_thumb_height);
			$imagethumb = imagecreatefromjpeg($filename);
			imagecopyresampled($image_t, $imagethumb, 0, 0, 0, 0, $new_thumb_width, $new_thumb_height, $width, $height);
			
			// Output
			imagejpeg($image_p, "$uploadfile", 100);
			imagejpeg($image_t, "$uploadTHfile", 100);
			
			$query = "INSERT INTO gallery VALUES ('','$imageName','$descriptionPost','$albumPost')";
			mysql_query($query, $connection) or die("Query failed : " . mysql_error());
						
			echo "Thank-you image has been added to the gallery.<br /><br />";
			echo "<a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>";
			} 
			else {
				echo "File upload is not valid.  Check permissions or contact the system administrator.";
				echo "<br /><br />";
				echo "<a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>";
			}
		}
} 	

	ELSE{
		//code to display the editor which replaces the textarea.
		  echo "<script type=\"text/javascript\" src=\""
          ."$docroot"
        ."editor/fckeditor.js\"></script>"
		."<script type=\"text/javascript\">"
 		."window.onload = function()"
 		."{"
 		."var oFCKeditor = new FCKeditor( 'description','','250','Default','' ) ;"
 		."oFCKeditor.BasePath	= '"
         ."$docroot"
        ."editor/' ;"
 		."oFCKeditor.ReplaceTextarea() ;"
 		."}"
 		."</script>";
 		//editor code end

		IF ($error==2){
		echo "<font color=\"red\">Please check to ensure that all fields have been filled.</font><br /><br />";
		$error==0;
		}
		
	echo "<table width=\"100%\">"
	     ."<form enctype=\"multipart/form-data\" action=\"default.php?$urlString&page=submit\"  method=\"POST\">"
					
			."<tr><td width=\"120\">"
			//<!-- Name of input element determines name in $_FILES array -->
			."<b>Choose Image: </b></td><td><input name=\"theImage[]\" type=\"file\" multiple/></td></tr>"
			."<tr><td width=\"80\"><strong>Add to Album:</strong></td><td>"
			."<select name=\"album\" size=\"1\">"
			."<option selected";
		     	if (($albumPost!=null)||($albumPost!="")){
				echo "value=\"$albumPost\">";
				$albumNameQuery = "SELECT * from galleryalbum where aid=$albumPost";
				$albumNameResult = mysql_query($albumNameQuery, $connection) or die("Query failed : " . mysql_error());
				$albumName = mysql_result($albumNameResult,0,"aname");	
				echo stripslashes($albumName);
			}
			else{
				echo ">";
			}
			 echo "</option>";
			
				$query = "SELECT * FROM galleryalbum";
				$result = mysql_query($query, $connection) or die("Query failed : " . mysql_error());
				$numrows = mysql_num_rows($result);
	
				for ($i = 0; $i < $numrows; $i++) {			
					$aname = mysql_result($result,$i,"aname");
					$aid = mysql_result($result,$i,"aid");
					
					echo "<option value=\"$aid\">";
					echo $aname;
					echo "</option>";
				}
				echo "</select>";
			echo "</td></tr>"
			
			."<tr><td colspan=\"2\" height=\"10\"></td></tr>"	
			."<tr><td colspan=\"2\"><b>Description:</b><br /></td></tr>"	
			."<tr><td colspan=\"2\" height=\"100\"><textarea name=\"description\" rows=\"8\" cols=\"75\">";
			if (($descriptionPost!=null)||($descriptionPost!="")){
				echo stripslashes($descriptionPost);
			}
			echo "</textarea></td></tr>"
			."<tr><td colspan=\"2\" height=\"10\"></td></tr>"	
						
			."<tr><td colspan=\"2\" height=\"10\">"
			."<input type=\"submit\" value=\"Submit\" />"
			."</td></tr>"
			."</form>"
			."</table>";
			
			echo "<br /><br /><a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>";
	}
}
}
}
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.