PHP - When You Click On Thumbnail I Want Image To Start Downloading (saving To Pc)
I am working on a simple gallery. I want to have an option to download full scale image without users having to right click and "save as". Using this code you get a image preview:
<a href="pictures/img-(1).jpg"><img src="thumbnails/img-(1).jpg"></a> How can I modify it so when user clicks on thumbnail of image 1 it will prompt him to save the image instead of viewing it. Thanks Similar Tutorialshey there peoples i have a bit of a problem with my php code. when i click on the name it wont play the video. but if i click on the thumbnail it plays here is the code Code: [Select] echo "<div class='Video_thumbnail'>"; echo "<a href='/Video.php?id={$row['id']}'>"; echo "<img src='http://i.ytimg.com/vi/{$row['link']}/hqdefault.jpg' width='220' height='170' alt='click' /></a>"; echo "<br>"; echo "</br>"; echo "<a href='/Video.php?={$row['id']}'>"; echo "{$row['navn']}</a>"; echo "</div>"; Hi All,
this is my first post after joining the forum.
First of all, I am not a programmer. My field is of Building design and Architecture. I work for an Architectural company.
I have a great interest in programming and I started learning php, mysql, html css and jscript, to develop a timesheet application for the company. The web application was created and successully implemented in April this year...! However, all these are purely 'self learning', and it has its own downsides as well. This was just a small intro..., let me come to what i request help on. This is for further development of the application.
I have a page to edit the 'utilization' rate of each employee, based on their designations. So the page has all the designations listed as <labels>, next to which a textbox, for the user to fill in the utilization rate. Scenario is that the user will not save each designation's utilization rate immediately after filling it. User will keep going till he fills the last item and then hit the submit button to save. Now, in php I can get all the values from the Request Array. But, how will I know which designations these values belong to? So, what i have as a solution is to name the textboxes with the designation_ids as suffix. May be like;
utilTextbox_1, utilTextbox_2, utilTextbox_3 etc...
Then when the form is submitted;
Check each Request Array element to see if its name starts with 'utilTextbox'
If Yes, split it using '_' to get the designation_id
Update the db table with the value of the text box
Check the next Array Element.....and so on...
is this the correct method or is there a better way of doing this?
The script for creating a new file name for the image:
$validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) $file_extension = end($ext); //store extensions in the variable $new_image_name = md5(uniqid()) . "." . $ext[count($ext) - 1]; $target_path = $target_path . $new_image_name;//set the target path with a new name of imageThe script creates a new file like: f6c9b8d9db05366c3504210cded9ddb2.jpgand moves the file to the "uploads" folder. And then the script also creates a thumbnail with the same file name and moves the file to the "thumbs" folder. The issue I am having is that the same ID code could happen again for a different image in the database, thus I would be calling a different original sized image than the thumbnail image. My question is: How to avoid this issue of the same ID code has happened again for a different file. What is the proper way to reference the anchor tag of the thumbnail image to its actual original sized image? With the script I have the thumbnail image would be coming from the "thumbs" folder and the anchor tag would get referenced to the "uploads" folder to get the original sized image. Edited by glassfish, 12 October 2014 - 05:51 AM. Hi I'm really new to php and could really do with some help. I am using the following script http://test.dpetroff.ru/jquery.iviewer.test/test/ which basically allows me to position an image within a DIV area My question is, how can I get PHP to save just the image within the DIV area, so it's almost acting like a crop tool I've tried a few things but so far not managed to get anything working Hi! my code uploads an image and saves it to an upload folder, but I want to create a thumbnail of it. For example, if I upload a 1400x1000 JPG, I would like to resize the image and it has to respect the proportion given a maximum size. if I say the maximum width/height is 250px, the image should be thumbnailed according to the max height/width, and in proportion with the width/height Thanks in advance Fernando Hello dear, I'm willing to use thumbnails into my website which is mainly like websites directory. I've been thinking to save url thumbnails into certain directory ! If i've index.php with the following image code (this would show thumbnail image of the website ANY_SITE.COM Code: [Select] <img src='http://thumbnails_provider.com/url=ANY_SITE.COM'/> then how to save the generated image into certain directory like my_site.com/thumbnails i've been thinking about Using cURL but i don't know how to apply it any help ~thanks Hi Guys, Using this code i am able to overlay a logo onto an image: <?php // Load the image where the logo will be embeded into $image = imagecreatefromjpeg("box.jpg"); // Load the logo image $logoImage = imagecreatefrompng("logo.png"); imagealphablending($logoImage, true); // Get dimensions $imageWidth=imagesx($image); $imageHeight=imagesy($image); $logoWidth=imagesx($logoImage); $logoHeight=imagesy($logoImage); // Paste the logo imagecopy( // source $image, // destination $logoImage, // destination x and y $imageWidth-$logoWidth, $imageHeight-$logoHeight, // source x and y 0, 0, // width and height of the area of the source to copy $logoWidth, $logoHeight); // Set type of image and send the output //header("Content-type: image/png"); //imagePng($image); imagejpeg($logoImage, "imageWithLogo.jpg", 100); // Release memory imageDestroy($image); imageDestroy($imageLogo); ?> this part: //header("Content-type: image/png"); //imagePng($image); shows me the complete image with the logo ontop, what i'm having trouble with is saving the image. any help would be appreciated thanks guys Graham I have a form where you can enter a image url and it's title. It calls display.php which displays the image as well as the title. But I want the image to be displayed as a thumbnail of size 150X100. Do i have to store it in directory before I convert it and display? If so, can somebody tell me how to convert the image into a thumbnail? Here is my code: Code: [Select] <table align="center" bgcolor="silver"> <form action="display.php" method ="post"> <tr> <td align="center"><b><font color="#214754" size="3">Reg</font></b></td> </tr> <tr> <td> Title: </td> <td><input type="text" size ="40" name="registry_title1" /></td> </tr> <tr> <td> Image URL: </td> <td><input type="text" size ="40" name="registry_img1" /></td> </tr> <tr> <td> <input type="submit" name="submit" value="submit" /> </td> </tr> </form> </table> </div> here is the code for display.php Code: [Select] <? /* Get Registry details */ $registry_img1=$_POST['registry_img1']; $registry_title1=stripslashes($_POST['registry_title1']); ?> <html> <body> <table width='600' cellspacing='0' cellpadding='0' border='0' bgcolor='#ffffff' align='center'> <tr> <td style='padding-bottom:8px';><font style='font-size:18px;color:rgb(0, 0, 0);text-decoration:none'><a style='font-size:18px;color:rgb(0, 0, 0);text-decoration:none' href='#'><? echo ucfirst($url); ?> Registry</font></a></td> </tr> <tr> <td style='padding-bottom:10px;'> <a style='color:rgb(206, 0, 0);font-size:14px;font-weight:bold;line-height:18px;text-decoration:none' href='<? echo $registry_url1; ?>' target='_blank'><img style='padding-right:10px' border='0' align='left' alt='' src='<? echo $registry_img1; ?>'><? echo $registry_title1;?> </a> </td> </table> </body> </html> Im trying to write an image upload script which checks various elements of the image and then saves it and and a thumbnail into a folder. At the moment I am getting a white screen which makes me think I have a syntax error so I have come here to find some fresh eyes to help me out. Can anyone see any reason why this wouldn't be working? Form Code: [Select] <form enctype='multipart/form-data' action='upload_image.php' method='POST'> <table class='uploads-form'> <tr> <td><input name='image' type='file' /><input type='hidden' name'MAX_FILE_SIZE' value='5000000' /></td> </tr> <tr> <td><input type='submit' name='upload_image' value='Upload' /></td> </tr> </table> </form> php <?php error_reporting(E_ALL); ini_set("display_errors", 1); $images_location = "project_files/"; $thumbs_location = "project_thumbs/"; $thumb_width = "100"; $maximum_size = "5000000"; //Auto Thumbnail Function function create_thumbnail($source,$destination, $thumb_width) { $size = getimagesize($source); $width = $size[0]; $height = $size[1]; $x = 0; $y = 0; if($width> $height) { $x = ceil(($width - $height) / 2 ); $width = $height; } elseif($height> $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_image = imagecreatetruecolor($thumb_width,$thumb_width) or die('Cannot initialize new GD image stream'); $extension = get_image_extension($source); if($extension=='jpg' || $extension=='jpeg') $image = imagecreatefromjpeg($source); if($extension=='gif') $image = imagecreatefromjpeg($source); if($extension=='png') $image = imagecreatefromjpeg($source); imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width,$thumb_width,$width,$height); if($extension=='jpg' || $extension=='jpeg') imagejpeg($new_image,$destination); if($extension=='gif') $imagegif($new_image,$destination); if($extension=='png') imagepng($new_image,$destination); } //Get Extension Function function get_image_extension($name) { $name = strtolower($name); $i = strrpos($name,"."); if (!$i) { return ""; } $l = strlen($name) - $i; $extension = substr($name,$i+1,$l); return $extension; } //Random Name Function function random_name($length) { $characters = "abcdefghijklmnopqrstuvwxyz01234567890"; $name = ""; for ($i = 0; $i < $length; $i++) { $name .= $character[mt_rand(0, strlen($characters) - 1)]; } return "image-".$name; } //Check And Save Image if(isset($_POST['upload_image'])) { if($_FILES['image']['name'] == ""){ echo = "Please select the image you would like to upload by clicking browse"; } else{ $size=filesize($_FILES['image']['tap_name']); $filename = stripslashes($_FILES['image']['name']); $extension = get_image_extension($filename); if($size > $maximum_size) { echo = "Your file size exceeds the maximum file size!"; } else if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo = "Only the following extensions are allowed. 'jpg', 'jpeg', 'png', 'gif'."; } else { $image_random_name=random_name(15).".".$extension; $copy = @copy($_FILES['image']['tmp_name'], $images_location.$image_random_name); if (!$copy) { echo = "Error while uploadin your image! Please try again!"; } else{ create_thumbnail($images_location.$image_random_name,$thumbs_location.$image_random_name, $thumb_width); echo = "Your image has been uploaded!"; } } } } ?> Hi, I have a script that uploads an image to a directory and then saves the fill path to a field in a table for later use. The only problem is people are uploading huge images and then when I produce a catalogue of my listings it takes forever to load because the images are so big. What I am after is an add in script to create an ADDITIONAL image 100 x 75px, I don't really want to change my upload script. Any ideas? Thanks in advace. Here is what I have: Code: [Select] <?php $idir = "../fleet/"; // Path To Images Directory if (isset ($_FILES['fupload'])){ //upload the image to tmp directory $url = $_FILES['fupload']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['fupload']['type'] == "image/jpg" || $_FILES['fupload']['type'] == "image/jpeg" || $_FILES['fupload']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['fupload']['name'], '$account.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php $copy = copy($_FILES['fupload']['tmp_name'], "$idir" . $_FILES['fupload']['name']); // Move Image From Temporary Location To Perm } } $fleetimage1 = mysql_real_escape_string("$idir" . $_FILES['fupload']['name']); //then insert sql code below... ?> Help me I am getting Notice: Undefined index: extension Hello. I'm using an Amazon S3 class to uploaded to S3. I have 2 upload boxes - The first uploads once and the second needs to upload twice - 1 full size, 1 thumb. The issue i'm having is that the 2nd image (the thumb) seems to be failing, although if I don't save the first full sized image I am able to upload the thumb. So I think the issue is with using the temp file twice? This is my code: //retreive post variables $fileName = $randomString . "_" . $_FILES['theFile']['name']; $fileTempName = $_FILES['theFile']['tmp_name']; $fileName2 = $randomString . "_" . $_FILES['theFile2']['name']; $fileTempName2 = $_FILES['theFile2']['tmp_name']; //move the file if ($s3->putObjectFile($fileTempName, "containerhere", $fileName, S3::ACL_PUBLIC_READ)) { echo "<strong>Uploaded Image</strong>"; }else{ echo "<strong>Something went wrong while uploading your file... sorry.</strong>"; } //move the file if ($s3->putObjectFile($fileTempName2, "containerhere", $fileName2, S3::ACL_PUBLIC_READ)) { echo "<strong>Uploaded Image</strong>"; }else{ echo "<strong>Something went wrong while uploading your file... sorry.</strong>"; } include('simpleImage.php'); $image = new SimpleImage(); $image->load($_FILES['theFile2']['tmp_name']); $image->resizeToWidth(100); $image->save($_FILES['theFile2']['tmp_name']); $fileName3 = $randomString . "_" . $_FILES['theFile2']['name']; $fileTempName3 = $_FILES['theFile2']['tmp_name']; //move the file if ($s3->putObjectFile($fileTempName3, "containerhere", "thumbs/" . $fileName3, S3::ACL_PUBLIC_READ)) { echo "<strong>Uploaded Image</strong>"; }else{ echo "<strong>Something went wrong while uploading your file... sorry.</strong>"; } Can anyone offer any advice? Thanks. Hey. I'm just wondering what would be the most logical or most efficient way to save an image resource that has been constructed on say the www. to a subdirectory or on another webserver? For eg The script on www.example.com constructs an image using the GD library from image1.png and image2.png. It has now got the final image resource for what's been constructed. I now want to save this image onto images.example.com How would you suggest? Hi, I am trying to make a simple thumbnail gallery where you upload an image, the image gets resized, a thumbnail is created in the "images/small/" directory, and the main images are in the "images/" directory. I need to somehow read from both directories, and do an image link with the thumbnail linking to the larger image. I think that means displaying from two directories, I don't know how to do that, please any help greatly appreciated. Thank you. here is my code so far Code: [Select] <?php error_reporting(0); $change=""; $abc=""; define ("MAX_SIZE","400"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if($_SERVER["REQUEST_METHOD"] == "POST") { $image =$_FILES["file"]["name"]; $uploadedfile = $_FILES['file']['tmp_name']; if ($image) { $filename = stripslashes($_FILES['file']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $change='<div class="msgdiv">Unknown Image extension </div> '; $errors=1; } else { $size=filesize($_FILES['file']['tmp_name']); if ($size > MAX_SIZE*1024) { $change='<div class="msgdiv">You have exceeded the size limit!</div> '; $errors=1; } if($extension=="jpg" || $extension=="jpeg" ) { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); } else if($extension=="png") { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefrompng($uploadedfile); } else { $src = imagecreatefromgif($uploadedfile); } echo $scr; list($width,$height)=getimagesize($uploadedfile); //**Original**// //$newwidth=60; //$newheight=($height/$width)*$newwidth; //**Modified to use height instead of width**// //$newheight=350; //$newwidth=($width/$height)*$newheight; // **IF NOT resizing full image then just pass variables.**// $newheight=$height; $newwidth=$width; //***adjust tmp***// $tmp=imagecreatetruecolor($newwidth,$newheight); //Thumbs $newheight1=180; $newwidth1=($width/$height)*$newheight1; //**Original**// //$newwidth1=25; //$newheight1=($height/$width)*$newwidth1; $tmp1=imagecreatetruecolor($newwidth1,$newheight1); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height); $filename = "images/". $_FILES['file']['name']; $filename1 = "images/small/". $_FILES['file']['name']; imagejpeg($tmp,$filename,100); imagejpeg($tmp1,$filename1,100); imagedestroy($src); imagedestroy($tmp); imagedestroy($tmp1); }} } //If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { // mysql_query("update {$prefix}users set img='$big',img_small='$small' where user_id='$user'"); $change=' <div class="msgdiv">Image Uploaded Successfully!</div>'; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <meta content="en-us" http-equiv="Content-Language"> <title>picture demo</title> <link href=".css" media="screen, projection" rel="stylesheet" type="text/css"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script> <script type="text/javascript" src="js/jquery_002.js"></script> <script type="text/javascript" src="js/displaymsg.js"></script> <script type="text/javascript" src="js/ajaxdelete.js"></script> <style type="text/css"> .help { font-size:11px; color:#006600; } body { color: #000000; background-color:#999999 ; background:#999999 url(<?php echo $user_row['img_src']; ?>) fixed repeat top left; font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif; } .msgdiv{ width:759px; padding-top:8px; padding-bottom:8px; background-color: #fff; font-weight:bold; font-size:18px;-moz-border-radius: 6px;-webkit-border-radius: 6px; } #container{width:763px;margin:0 auto;padding:3px 0;text-align:left;position:relative; -moz-border-radius: 6px;-webkit-border-radius: 6px; background-color:#FFFFFF } </style> </head><body> <div align="center" id="err"> <?php echo $change; ?> </div> <div id="space"></div> <div id="container" > <div id="con"> <table width="502" cellpadding="0" cellspacing="0" id="main"> <tbody> <tr> <td width="500" height="238" valign="top" id="main_right"> <div id="posts"> <img src="<?php echo $filename; ?>" /> <img src="<?php echo $filename1; ?>" /> <form method="post" action="" enctype="multipart/form-data" name="form1"> <table width="500" border="0" align="center" cellpadding="0" cellspacing="0"> <tr><Td style="height:25px"> </Td></tr> <tr> <td width="150"><div align="right" class="titles">Picture : </div></td> <td width="350" align="left"> <div align="left"> <input size="25" name="file" type="file" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10pt" class="box"/> </div></td> </tr> <tr><Td></Td> <Td valign="top" height="35px" class="help">Image maximum size <b>400 </b>kb</span></Td> </tr> <tr><Td></Td><Td valign="top" height="35px"><input type="submit" id="mybut" value=" Upload " name="Submit"/></Td></tr> <tr> <td width="200"> </td> <td width="200"><table width="200" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="200" align="center"><div align="left"></div></td> <td width="100"> </td> </tr> </table></td> </tr> </table> </form> </div> </td> </tr> </tbody> </table> </div> </div> </body></html> I am working on an uploader and slowly getting it working, I am uploading 3 images at once, and setting arrays for each one as keys, with an increment of ++1. I am wanting to resize the image before it gets copied to the thumbnail folder. I have this code.
Everything works with it. As you see, I started on getting the file info, but after that I am totally stuck on what to do after to resize the image proportionally with a maximum width of xPX and height to match it without looking distorted. Any help would be really appreciated. Thank You. Hi All, This is my first post on here. I'd really appreciate any help with this, it's driving me mad. I'm trying to create a form to save a image into a mySQL database. I have a website hosted by UK2.net which has a mysql db with a table called gallery(name (varchar 30), size (int), type varchar(30), thePic(mediumBlob)). I have a form with this: Code: [Select] <td><p><label>Pic: </label></td><td><input name="userfile" type="file" id="userfile" /></td></p> Which when submitted actions addImage.php. The code for this looks like this: Code: [Select] <?php $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $con = mysql_connect("localhost", "userName", "password") or die(mysql_error()); mysql_select_db("dbName", $con) or die(mysql_error()); $query = "INSERT INTO gallery (name, size, type, thePic) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; if (!mysql_query($query,$con)) { die('Error: ' . mysql_error()); } echo "<br>File $fileName uploaded<br>"; ?> I get the following error message: Quote Warning: fopen() [function.fopen]: Filename cannot be empty in /home/hiddenje/public_html/addImage.php on line 13 Does anyone know what this is about? I've been on out friend google and a lot of people seem to be pointing to permissions but I can't seem to apply it to my scenario and just can't get it to work. Im a developer by trade, but this is my first step into the...interesting world of PHP and mySQL. Again, I'd appreciate any help with this. I'd love someone to talk me through exactly what I'm missing or doing wrong. Thanks in advance. Greetings, What I'm trying to do is have users upload their event information into a database which would include a flyer. I don't want the image file to go into the database (other than the filename) rather I'd like it to be dropped into a directory. In the same script I'd like to dynamically generate a thumbnail. I have the two scripts and separately they work fine, but I can't get them to work together. I'm guessing the conflict because the thumbnail script is using $_POST and the mysql script is using $_SESSION. If so how can I modify them to both use $_SESSION? The thumbnail script is goes from line 1 - 146 and the mysql portion is the rest. The results of processing this look something like this. QUERY TEXT: INSERT INTO td_events (eventgenre_sel, eventname, eventvenue, eventdate, eventgenre, eventprice, eventpromoter, eventflyer) VALUES ('12', 'spooky times', 'Ironwood Stage & Grill', '2010-12-17 22:36:00', 'DNB', '5000', 'me', '174366-1.jpg') <?php $debug = FALSE; /********************************************************************************************** CREATES THUMBNAIL **********************************************************************************************/ //define a maxim size for the uploaded images define ("MAX_SIZE","1024"); // define the width and height for the thumbnail // note that theese dimmensions are considered the maximum dimmension and are not fixed, // because we have to keep the image ratio intact or it will be deformed define ("WIDTH","500"); define ("HEIGHT","650"); // this is the function that will create the thumbnail image from the uploaded image // the resize will be done considering the width and height defined, but without deforming the image function make_thumb($img_name,$filename,$new_w,$new_h) { //get image extension. $ext=getExtension($img_name); //creates the new image using the appropriate function from gd library if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext) || !strcmp("JPG",$ext)) $src_img=imagecreatefromjpeg($img_name); if(!strcmp("png",$ext) || !strcmp("PNG",$ext)) $src_img=imagecreatefrompng($img_name); //gets the dimmensions of the image $old_x=imageSX($src_img); $old_y=imageSY($src_img); // next we will calculate the new dimmensions for the thumbnail image // the next steps will be taken: // 1. calculate the ratio by dividing the old dimmensions with the new ones // 2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable // and the height will be calculated so the image ratio will not change // 3. otherwise we will use the height ratio for the image // as a result, only one of the dimmensions will be from the fixed ones $ratio1=$old_x/$new_w; $ratio2=$old_y/$new_h; if($ratio1>$ratio2) { $thumb_w=$new_w; $thumb_h=$old_y/$ratio1; } else { $thumb_h=$new_h; $thumb_w=$old_x/$ratio2; } // we create a new image with the new dimmensions $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); // resize the big image to the new created one imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // output the created image to the file. Now we will have the thumbnail into the file named by $filename if(!strcmp("png",$ext)) imagepng($dst_img,$filename); else imagejpeg($dst_img,$filename); //destroys source and destination images. imagedestroy($dst_img); imagedestroy($src_img); } // This function reads the extension of the file. // It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } // This variable is used as a flag. The value is initialized with 0 (meaning no error found) // and it will be changed to 1 if an error occurs. If the error occurs the file will not be uploaded. $errors=0; // checks if the form has been submitted if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $image=$_FILES['eventflyer']['name']; // if it is not empty if ($image) { // get the original name of the file from the clients machine $filename = stripslashes($_FILES['eventflyer']['name']); // get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); // if it is not a known extension, we will suppose it is an error, print an error message // and will not upload the file, otherwise we continue if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "JPG") && ($extension != "PNG") && ($extension != "png")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { // get the size of the image in bytes // $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which // the uploaded file was stored on the server $size=getimagesize($_FILES['eventflyer']['tmp_name']); $sizekb=filesize($_FILES['eventflyer']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($sizekb > MAX_SIZE*500) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name=$filename; //the new name will be containing the full path where will be stored (images folder) $newname="flyers/".$image_name; $copied = copy($_FILES['eventflyer']['tmp_name'], $newname); //we verify if the image has been uploaded, and print error instead if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; } else { // the new thumbnail image will be placed in images/thumbs/ folder $thumb_name='flyers/thumb_'.$image_name; // call the function that will create the thumbnail. The function will get as parameters // the image name, the thumbnail name and the width and height desired for the thumbnail $thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT); }} }} //If no errors registred, print the success message and show the thumbnail image created if(isset($_POST['Submit']) && !$errors) { echo "<h1>Thumbnail created Successfully!</h1>"; echo '<img src="'.$thumb_name.'">'; } /************************************************************ Adjust the headers... ************************************************************/ header("Expires: Thu, 17 May 2001 10:17:17 GMT"); // Date in the past header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 /***************************************************************************** Check the session details. we will store all the post variables in session variables this will make it easier to work with the verification routines *****************************************************************************/ session_start(); if (!isset($_SESSION['SESSION'])) require_once( "../include/session_init.php"); $arVal = array(); require_once("../include/session_funcs1.php"); reset ($_POST); while (list ($key, $val) = each ($_POST)) { if ($val == "") $val = "NULL"; $arVals[$key] = (get_magic_quotes_gpc()) ? $val : addslashes($val); if ($val == "NULL") $_SESSION[$key] = NULL; else $_SESSION[$key] = $val; if ($debug) echo $key . " : " . $arVals[$key] . "<br>"; } /********************************************************************************************** Make sure session variables have been set and then check for required fields otherwise return to the registration form to fix the errors. **********************************************************************************************/ // check to see if these variables have been set... if ((!isset($_SESSION["eventname"])) || (!isset($_SESSION["eventvenue"])) || (!isset($_SESSION["eventdate"])) || (!isset($_SESSION["eventgenre"])) || (!isset($_SESSION["eventprice"])) || (!isset($_SESSION["eventpromoter"])) || (!isset($_SESSION["eventflyer"]))) { resendToForm("?flg=red"); } // form variables must have something in them... if ($_SESSION['eventname'] == "" || $_SESSION['eventvenue'] == "" || $_SESSION['eventdate'] == "" || $_SESSION['eventgenre'] == "" || $_SESSION['eventprice'] == "" || $_SESSION['eventpromoter'] == "" || $_SESSION['eventflyer'] == "") { resendToForm("?flg=red"); } /********************************************************************************************** Insert into the database... **********************************************************************************************/ $conn = mysql_connect($_SESSION['MYSQL_SERVER1'],$_SESSION['MYSQL_LOGIN1'],$_SESSION['MYSQL_PASS1']) or die ('Error connecting to mysql'); mysql_select_db($_SESSION['MYSQL_DB1']) or die("Unable to select database"); $eventgenre_sel = addslashes($_REQUEST['eventgenre_sel']); $eventname = addslashes($_REQUEST['eventname']); $eventvenue = addslashes($_REQUEST['eventvenue']); $eventdate = addslashes($_REQUEST['eventdate']); $eventgenre = addslashes($_REQUEST['eventgenre']); $eventprice = addslashes($_REQUEST['eventprice']); $eventpromoter = addslashes($_REQUEST['eventpromoter']); $eventflyer = addslashes($_REQUEST['eventflyer']); $sqlquery = "INSERT INTO td_events (eventgenre_sel, eventname, eventvenue, eventdate, eventgenre, eventprice, eventpromoter, eventflyer) " ."VALUES ('$eventgenre_sel', '$eventname', '$eventvenue', '$eventdate', '$eventgenre', '$eventprice', '$eventpromoter', '$eventflyer')"; echo 'QUERY TEXT:<br />'.$sqlquery; $result = MYSQL_QUERY($sqlquery); $insertid = mysql_insert_id(); /*** This following function will update session variables and resend to the form so the user can fix errors ***/ function resendToForm($flags) { reset ($_POST); // store variables in session... while (list ($key, $val) = each ($_POST)) { $_SESSION[$key] = $val; } // go back to the form... //echo $flags; header("Location: /user_registration.php".$flags); exit; } mysql_close($conn); ?> Hi, I have an image map mixed in with php, and it won't click when I click the mouse on it, it won't work. Any help greatly appreciated. Thanks. Derek here is the code where I use it. Code: [Select] if(isset($_GET['newLocation'])) { $_SESSION['current_location']=$_GET['newLocation']; } if(!isset($_SESSION['current_location']) && !isset($_SESSION['current_background']) && !isset($_SESSION['currentMonster'])) { $_SESSION['current_location'] = 0; $_SESSION['current_monster'] = 0; $_SESSION['current_background'] = 0; } if($_SESSION['current_location'] != 0) { if(!isset($_SESSION['current_background']) && !isset($_SESSION['current_monster'])) { $_SESSION['current_monster'] = 0; $_SESSION['current_background'] = 0; } if(isset($_GET['further'])) { //below is- inside the locations array, teardrop ocean (1) the background image is 4(example)+1 is set, then //do this if(isset($locations[$_SESSION['current_location']]['background_images'][$_SESSION['current_background']+1])) { $_SESSION['current_background']+=1; } if(isset($locations[$_SESSION['current_location']]['monster_images'][$_SESSION['current_monster']+1])) { $_SESSION['current_monster']+=1; } } elseif(isset($_GET['back'])) { if(isset($locations[$_SESSION['current_location']]['background_images'][$_SESSION['current_background']-1])) { $_SESSION['current_background']-=1; } if(isset($locations[$_SESSION['current_location']]['monster_images'][$_SESSION['current_monster']-1])) { $_SESSION['current_monster']-=1; } } // I dont have any $_SESSION['background'] var //$currentBackground=$_SESSION['background'][$_SESSION['current_background']]; $currentBackground = $locations[$_SESSION['current_location']]['background_images'][$_SESSION['current_background']]; //I dont have any $_SESSION['monster'] var //$currentMonster=$_SESSION['monster'][$_SESSION['current_monster']]; $currentMonster=$locations[$_SESSION['current_location']]['monster_images'][$_SESSION['current_monster']]; } else { //?newLocation=1 means set it to Teardrop ocean. $currentBackground = ' <img src="aradia.jpg" width="256" height="328" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="5,176,81,249" href="?newLocation=1"/> </map>'; $currentMonster = ''; } I am trying to have an UPDATE query run when I click an image on a web page. I just need to have the image call the function to run the mysql from the corresponding php file. The image is a form object, which I need the php function to recognize when it is clicked, and then run the query(ies) within. I don't really know much php, so the php code is based on a snippet I have from one of my other sites, which works fine over there, but I am missing something here that is keeping it from doing the same here. The page already loads and displays all values in a list associated with $show_id, so that variable is already being pulled from the web page in to the php code. I'm not going to paste the entire books.php file here as there are too many things it does which doesnt have anything to do with this little add-on I am making. I just need to be able to pull that variable in to the query below and have it run when I click on the icon associated with it. The php file also already has the proper config and settings files linked to it that connect to the database, so I do not need to set that up here. It is just a form, calling a function, and running the query. It is also not visible to the user side. It is in an admin page, only visible and accessible to me. This is code I have in the php file: function UpdateAllShowBooks() { if(strlen(($_POST['retired'])) > 0){ $sql = "UPDATE ttb_books SET status_id = '2' WHERE show_id='$show_id'"; $db = new database(); $db->myquery($sql, 1); header('Location:books.php?show_id=$show_id'); die(); } if(strlen(($_POST['upcoming'])) > 0){ $sql = "UPDATE ttb_books SET status_id = '37' WHERE show_id='$show_id'"; $db = new database(); $db->myquery($sql, 1); header('Location:books.php?show_id=$show_id'); die(); } if(strlen(($_POST['current'])) > 0){ $sql = "UPDATE ttb_books SET status_id = '1' WHERE show_id='$show_id'"; $db = new database(); $db->myquery($sql, 1); header('Location:books.php?show_id=$show_id'); die(); } } This is the current image/form html: <center><table width=25%> <tr><td valign="top" align="center"> <!--<form method="post" action="books.php?show_id={show_id}">--> <form method="post" action="books.php" name="retired"> <input type="image" src="../images/icon-Red_Light.png" width="20" name="retired" alt="Set status to Out of Print" title="Set status to Out of Print" onclick="return confirm('Set ALL status to Out of Print?')"> <input name="shid1" type="hidden" id="shid1" value="{show_id}" /> </form> </td><td valign="top" align="center"> <form method="post" action="books.php" name="upcoming"> <input type="image" src="../images/icon-Yellow_Light.png" width="20" name="upcoming" alt="Set status to Upcoming Release" title="Set status to Upcoming Release" onclick="return confirm('Set ALL status to Upcoming Release?')"> <input name="shid2" type="hidden" id="shid2" value="{show_id}" /> </form> </td><td valign="top" align="center"> <form method="post" action="books.php" name="current"> <input type="image" src="../images/icon-Green_Light.png" width="20" name="current" alt="Set status to In Print" title="Set status to In Print" onclick="return confirm('Set ALL status to In Print?')"> <input name="shid3" type="hidden" id="shid3" value="{show_id}" /> </form> </td></tr> </table></center> So clicking on the form image would call the function with that mysql string and update all items in the list accordingly. At this time, when I click the image, it reloads the page fine, but it is not activating the sql in the function and making the Update occur. Thank you for any help you can provide. I really appreciate it. Hi, I currently have this code which displays text on clicking the image: <a href="javascript:;" onclick="document.getElementById('text').style.display='block';window.open('url...');"><img src="image..."></a> <div id="text" style="display:none;"> ...text to be displayed here </div> it works fine but I want to integrate this with php which is where I am struggling. I have a mySQL database with 4 fields (id;name;description;url), what i would like to do is name the div to be opened on click with the 'id' field from the database so that it would become '<div id="id"> and then more than one function could be implemented on each page. I would also like to replace '...text to be displayed here' with the field 'name' from the database and '...url' with the field 'url from the database. Any help would be very much appreciated. Thanks in advance. |