PHP - How To Move Copy Image When Original Image Dragend In Kineticjs
After image is drop into container , I want to move copy of the original image to be move when original image dragend within container. I tried but it display copy image each time when original image dragend. can anyone help me?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Prototype</title> <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> <script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.7.2.min.js"></script> <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.min.js"></script> <style> body{padding:20px;} #container{ border:solid 1px #ccc; margin-top: 10px; width:350px; height:350px; } #toolbar{ width:350px; height:35px; border:solid 1px blue; } </style> <script> $(function(){ var $house=$("#house"); $house.hide(); var $stageContainer=$("#container"); var stageOffset=$stageContainer.offset(); var offsetX=stageOffset.left; var offsetY=stageOffset.top; var stage = new Kinetic.Stage({ container: 'container', width: 350, height: 350 }); var layer = new Kinetic.Layer(); stage.add(layer); var image1=new Image(); image1.onload=function(){ $house.show(); } image1.src="http://vignette1.wikia.nocookie.net/angrybirds/images/b/b6/Small.png/revision/latest?cb=20120501022157"; $house.draggable({ helper:'clone', }); $house.data("url","house.png"); // key-value pair $house.data("width","32"); // key-value pair $house.data("height","33"); // key-value pair $house.data("image",image1); // key-value pair $stageContainer.droppable({ drop:dragDrop, }); function dragDrop(e,ui){ var x=parseInt(ui.offset.left-offsetX); var y=parseInt(ui.offset.top-offsetY); var element=ui.draggable; var data=element.data("url"); var theImage=element.data("image"); var image = new Kinetic.Image({ name:data, x:x, y:y, image:theImage, draggable: true, dragBoundFunc: function(pos) { return { x: pos.x, y: this.getAbsolutePosition().y } } }); image.on("dragend", function(e) { var points = image.getPosition(); var image1 = new Kinetic.Image({ name: data, id: "imageantry", x: points.x+65, y: points.y, image: theImage, draggable: false }); layer.add(image1); layer.draw(); }); image.on('dblclick', function() { image.remove(); layer.draw(); }); layer.add(image); layer.draw(); } }); // end $(function(){}); </script> </head> <body> <div id="toolbar"> <img id="house" width=32 height=32 src="http://vignette1.wikia.nocookie.net/angrybirds/images/b/b6/Small.png/revision/latest?cb=20120501022157"><br> </div> <div id="container"></div> </body> </html> Edited by Biruntha, 08 January 2015 - 10:14 AM. Similar TutorialsThe 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. This resizer works fine except I would like it to save the original image AND the thumbnail. Right now its only saving the cropped thumbnail. It's seems simple enough but I've tried several different ways but can't get it to work. :( I would appreciate your help. :) define( 'DESIRED_IMAGE_WIDTH', 150 ); define( 'DESIRED_IMAGE_HEIGHT', 150 ); $source_path = $_FILES[ 'thumb' ][ 'tmp_name' ]; $timestamp = time(); $target = "image_files/".$imagename; move_uploaded_file($source, $target); // // Add file validation code here // list( $source_width, $source_height, $source_type ) = getimagesize( $source_path ); switch ( $source_type ) { case IMAGETYPE_GIF: $source_gdim = imagecreatefromgif( $source_path ); break; case IMAGETYPE_JPEG: $source_gdim = imagecreatefromjpeg( $source_path ); break; case IMAGETYPE_PNG: $source_gdim = imagecreatefrompng( $source_path ); break; } $source_aspect_ratio = $source_width / $source_height; $desired_aspect_ratio = DESIRED_IMAGE_WIDTH / DESIRED_IMAGE_HEIGHT; if ( $source_aspect_ratio > $desired_aspect_ratio ) { // // Triggered when source image is wider // $temp_height = DESIRED_IMAGE_HEIGHT; $temp_width = ( int ) ( DESIRED_IMAGE_HEIGHT * $source_aspect_ratio ); } else { // // Triggered otherwise (i.e. source image is similar or taller) // $temp_width = DESIRED_IMAGE_WIDTH; $temp_height = ( int ) ( DESIRED_IMAGE_WIDTH / $source_aspect_ratio ); } // // Resize the image into a temporary GD image // $temp_gdim = imagecreatetruecolor( $temp_width, $temp_height ); imagecopyresampled( $temp_gdim, $source_gdim, 0, 0, 0, 0, $temp_width, $temp_height, $source_width, $source_height ); // // Copy cropped region from temporary image into the desired GD image // $x0 = ( $temp_width - DESIRED_IMAGE_WIDTH ) / 2; $y0 = ( $temp_height - DESIRED_IMAGE_HEIGHT ) / 2; $desired_gdim = imagecreatetruecolor( DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); imagecopy( $desired_gdim, $temp_gdim, 0, 0, $x0, $y0, DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); // // Render the image // Alternatively, you can save the image in file-system or database // header( 'Content-type: image/jpeg' ); imagejpeg( $desired_gdim, "image_files/" . $timestamp . $_FILES["thumb"]["name"] ); Hi guys, I am wirting a script to upload an image file, but I get the error: copy() [function.copy]: Filename cannot be empty in Obviouly it has something to do with the copy() function - (copy($HTTP_POST_FILES['product_img']['tmp_name'], $path)) I think it is not copying from my temp folder or something. Can anyone help me out? Code is: Code: [Select] //IMAGE FILE $file_name = $_FILES['product_img']['name']; echo '<p>File Name:' . $file_name . '</p>'; //IMAGE UPLOAD // random 4 digit to add to file name $random_digit=rand(0000,9999); //combine random digit to file name to create new file name //use dot (.) to combile these two variables $new_image_name = $random_digit.$file_name; echo $new_image_name; //SET DESINATION FOLDER $path= "uploads/".$new_image_name; echo '<p>Path:' . $path . '</p>'; if($product_img !=none) { if(copy($HTTP_POST_FILES['product_img']['tmp_name'], $path)) { echo "Successful<BR/>"; echo "File Name :".$new_file_name."<BR/>"; echo "File Size :".$HTTP_POST_FILES['product_img']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['product_img']['type']."<BR/>"; } else { echo "Image upload Error<BR/>"; } } Any help would be greatly appreciated! Thanks hey all, I've been struggling with this for the last few days and can't figure it out... I'm trying to build a fairly complex uploading system. the thing i'm getting stuck with is trying to copy/move the uploaded files from the domain name to a subdomain Ex: $path1 = "/var/www/vhosts/domain.com/httpdocs/new/test/test.jpg"; $path2 = "/var/www/vhosts/domain.com/subdomains/img/httpdocs/test/test.jpg"; Dedicated server running RHEL with Plesk The problem seems to be an open_basedir restriction. My question is... are there any work-arounds open_basedir and if not what are the implications of disabling it??? Any help is greatly appreciated. Thank you for your time c enter code hereI am New to PHP but i did pull off (with help of a friend) this piece of code. i am stuck at the part to display Image (it is Blank) and move through records (nothing happens). This is the whole PHP code. Any positive response will be highly appreciated. Thanx in advance. I am trying to copy an image into another image. Code: [Select] $im = imagecreatefrompng("/oldimg.png"); //this is a semi-transparent image where I want the new image to be copied imagealphablending($im, 1); //this seems to remove the black background header('Content-type: image/png'); //outputs old image with a transparent background (YAY!) imagepng($im); imagecopy($im, $newimage, 32, 0, 0, 0, 32, 32); //I want to replace a part of the old image with a new semi-transparent image header('Content-type: image/png'); //outputs image with a black background (noooooooooo!) imagepng($im); Can anyone help me? Hello Everybody
I usually work with C#, but I'm doing a website right now and have a question:
I want a picture in my header and when I change the window size the image may not move.
My code so far:
#a1 { position: relative; top:-175px; left:0px; width:50px; height:50px; background-image:url(http://domain.png); background-repeat:no-repeat;} </style>Hope someone can answer this question easy could someone help in how to resize a uploaded image size, say if someone is uploading a 1mb photo to my server, i wish for it to become 100kb and also resize its width and height? here is my code Code: [Select] //////////////////////////////////////uploader else if($action=="uploader") { echo "Upload your picture and copy the link <br/>after uploading to user it at gallery.<br/><br/>"; echo "<form method=\"post\" enctype=\"multipart/form-data\" action=\"index.php?action=uploaded&sid=$sid\">"; echo "Choose Pictu <br />"; echo "<input name=\"uploaded\" type=\"file\" /><br /><br />"; echo "<input type=\"submit\" value=\"Upload\" />"; echo "</form><br/>"; echo "<p align=\"center\">"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } //////////////////////////////////////uploader else if($action=="uploaded") { $blacklist = array(".php", ".php.jpg", ".php.jpeg", ".php.gif", ".php.png", ".phtml", ".php3", ".php4"); foreach ($blacklist as $item) { if(preg_match("/$item\$/i", $_FILES['uploaded']['name'])) { echo "<p align=\"center\">"; echo "Oops sorry we do not allow those files.<br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; exit; } } $target = "../images/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if (file_exists("../images/" . $_FILES["uploaded"]["name"])) { echo "<p align=\"center\">"; echo $_FILES["file"]["name"] . "Oops file name already exists<br/> kindly rename your picture and upload again. <br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; }else{ //This is our size condition if ($uploaded_size > 25600){ echo "Your file is too large. We have a 25kb limit.<br/>"; $ok=0; } $types = array('image/jpeg', 'image/gif', 'image/png'); if (in_array($_FILES['uploaded']['type'], $types)) { // file is okay continue } else { $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0){ echo "<p align=\"center\">"; Echo "Sorry your file was not uploaded.<br/> It may be the wrong filetype. <br/>We only allow JPG, GIF, and PNG filetypes.<br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } //If everything is ok we try to upload it else{ if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){ echo "<p align=\"center\">"; echo "The file ". basename( $_FILES['uploadedfile']['name']). " Picture uploaded successfully.<br/><br/><b>$target <br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } else{ echo "<p align=\"center\">"; echo "Sorry, there was a problem uploading your file.<br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } } } } Hi there, on my yardmaps website, if a user uploads an image taken with an iphone, and the exif data sets orientation to 1, the image is automatically rotated when put through the imagecopyresampled function. If I take the same image, and strip out the exif data with photoshop (save as for web, no meta data), the image uploads correctly. Is there any way to force imagecopyresampled to not rotate the image? Thanks B Hi the file file upload whenever i upload an image to main directory it saves one image into photos folder and copy another into thumbs folder but whenever i upload image to a different album (not main directory) it doesnt copy the other image to thumbs folder what i'm i doing wrong this is the line that i chose the folder... function make_locations ($locs) { $html = '<select name="locations" class="input"><option value="0">-- Main Directory --</option>'; foreach ($locs AS $key => $value) { $html .= '<option value="' .$value['album_id']. '">' .addslashes($value['album_name']). '</option>'; } $html .= '</select>'; return $html; } this is the whole code <?php /** * create a sub album directory for photos * to be stored in */ function create_album ($album_name, $sub_album = 0) { global $db; $sql = "INSERT INTO " .ALBUMS_TABLE. " ( album_name, sub_album ) VALUES ( '" .addslashes($album_name). "', " .intval($sub_album). " )"; if ($db->query($sql)) { return TRUE; } else { return FALSE; } } /** * get a list of sub albums */ function get_albums ($sub_album = 0) { global $db; $sql = "SELECT * FROM " .ALBUMS_TABLE. " WHERE sub_album = " .intval($sub_album); $db->query($sql); // initialise album storage $albums = array(); while ($row = $db->fetch()) { $albums[] = $row; } return $albums; } /** * get a list of photos within an album */ function get_photos ($album = 0) { global $db; $sql = "SELECT * FROM " .PHOTOS_TABLE. " WHERE album_id = " .intval($album). " ORDER BY photo_id ASC"; $db->query($sql); // initialise album storage $photos = array(); while ($row = $db->fetch()) { $photos[] = $row; } return $photos; } /** * get a large version of a particular photo */ function get_large ($photo, $album = 0, $next = '') { global $db, $template, $account_details; // shall we get the next / previous photo switch ($next) { case "next" : $next_sql = "AND photo_id > " .intval($photo). " ORDER BY photo_id ASC"; break; case "previous" : $next_sql = "AND photo_id < " .intval($photo). " ORDER BY photo_id DESC"; break; default : $next_sql = "AND photo_id = " .intval($photo); break; } $sql = "SELECT * FROM " .PHOTOS_TABLE. " WHERE album_id = " .intval($album). " " .$next_sql. " LIMIT 1"; $db->query($sql); if ($db->num_rows() == 0) { return ''; } else { $photo_info = $db->fetch(); // note the total directory $location = 'photos/' .$photo_info['photo_proper']; // now we need to resize list($width, $height) = getimagesize($location); if ($width < 300) { $new_width = $width; $new_height = $height; } elseif ($width > $height) { $new_width = 300; $new_height = $height * ($new_width / $width); } elseif ($width < $height) { $new_width = $width * ($new_height / $height); $new_height = 300; } // work out the next link $next = '<a href="portfolio.php?p=' .$photo_info['photo_id']. '&a=' .$photo_info['album_id']. '&next=next">Next</a>'; $previous = '<a href="portfolio.php?p=' .$photo_info['photo_id']. '&a=' .$photo_info['album_id']. '&next=previous">Previous</a>'; return '<div id="largephoto"><img src="' .$location. '" height="' .$new_height. '" width="' .$new_width. '" class="large"><br /><div id="prevnext">' .$previous. ' :: ' .$next. '</div></div>'; } } /** * get an array of locations */ function get_locations () { global $db; // initialise array $locations = array(); // select albums $sql = "SELECT album_id, album_name FROM " .ALBUMS_TABLE; $db->query($sql); while ($row = $db->fetch()) { $locations[] = $row; } return $locations; } /** * make the locations table */ function make_locations ($locs) { $html = '<select name="locations" class="input"><option value="0">-- Main Directory --</option>'; foreach ($locs AS $key => $value) { $html .= '<option value="' .$value['album_id']. '">' .addslashes($value['album_name']). '</option>'; } $html .= '</select>'; return $html; } /** * delete an album from the database * does not delete the photos in it */ function delete_albums ($album_ids) { global $db; if (sizeof($album_ids) > 0) { $sql = "DELETE FROM " .ALBUMS_TABLE. " WHERE album_id IN (" .implode(',', $album_ids). ")"; if ($db->query($sql)) { return TRUE; } } return FALSE; } /** * delete a set of photos */ function delete_photos ($photo_ids) { global $db; if (sizeof($photo_ids) > 0) { // select photo names for deletion $sql = "SELECT photo_proper FROM " .PHOTOS_TABLE. " WHERE photo_id IN (" .implode(',', $photo_ids). ")"; $db->query($sql); $unlink_ids = array(); while ($row = $db->fetch()) { $unlink_ids[] = $row['photo_proper']; } // now delete the photos if (sizeof($unlink_ids) > 0) { $sql = "DELETE FROM " .PHOTOS_TABLE. " WHERE photo_id IN (" .implode(',', $photo_ids). ")"; if ($db->query($sql)) { // remove photo from directory for ($i = 0; $i < sizeof($unlink_ids); $i++) { unlink("photos/" .$unlink_ids[$i]); unlink("photos/thumbs/" .$unlink_ids[$i]); } return TRUE; } } } return FALSE; } /** * upload a set of files */ function upload_files ($save_dir = '', $album = 0) { global $db; // check the save dir is writable if (!is_writable($save_dir)) { return FALSE; } // specify allowed file types $allowed_types = array ( 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif' ); // keep a list of uploaded files $uploaded = array(); // store bytes uploaded $total_bytes = 0; // go through the list of files while (list($key, $value) = each($_FILES['userfile']['name'])) { // check file has been passed if (!empty($value)) { // find extension $extension = substr($_FILES['userfile']['name'][$key], strpos($_FILES['userfile']['name'][$key],".") + 1); // time + $key for name $name = time(). "_" .$key. "." .$extension; // save url $add = $save_dir. "/" .$name; if (move_uploaded_file($_FILES['userfile']['tmp_name'][$key], $add)) { chmod($add, 0777); // add photo to database create_photo($_FILES['userfile']['name'][$key], $name, $album); } } } return TRUE; } /** * insert photo details into the database */ function create_photo ($photo_name, $key_name, $album = 0) { global $db; // get the filesize if (!$size = filesize("photos/" .$key_name)) { $size = 0; } // insert the photo in the database $sql = "INSERT INTO " .PHOTOS_TABLE. " ( photo_name, photo_date, photo_proper, photo_size, album_id ) VALUES ( '" .addslashes($photo_name). "', " .time(). ", '" .addslashes($key_name). "', " .intval($size). ", " .$album. " )"; if ($db->query($sql)) { return TRUE; } else { return FALSE; } } /** * get a complete raw copy of the directory */ function get_dir_contents ($dir) { // declare content array $contents = array(); // check gallery exists if (is_dir($dir)) { if ($handle = opendir($dir)) { while (FALSE !== ($file = readdir($handle))) { if ($file != '.' && $file != '..' && $file != 'thumbs') { if (file_exists($dir. '/thumbs/' .$file) || thumbnail($file, $dir. '/' .$file, $dir. '/thumbs')) { $contents[] = $dir. '/thumbs/' .$file; } else { $contents[] = 'no_image.gif'; } } } } } return $contents; } /** * create a thumbnail of a photo and store it * in the thumbs directory */ function thumbnail ($filename, $source_file, $destination, $new_h = 75, $new_w = 75) { if (!is_file($source_file)) { return FALSE; } // get the image details list($old_w, $old_h, $type) = getimagesize($source_file); // create source image switch($type) { case 1: $source = @imagecreatefromgif($source_file); break; case 2: $source = @imagecreatefromjpeg($source_file); break; case 3: $source = @imagecreatefrompng($source_file); break; default : return FALSE; } // work out dimensions if ($old_w < $old_h) { $thumb_w = $new_w; $thumb_h = $old_h * ($new_h / $old_w); } elseif ($old_w > $old_h) { $thumb_w = $old_w * ($new_w / $old_h); $thumb_h = $new_h; } elseif ($old_w == $old_h) { $thumb_w = $new_w; $thumb_h = $new_h; } $thumb = @imagecreatetruecolor($thumb_w, $thumb_h); // create image imagecopyresized($thumb, $source, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_w, $old_h); // check we have a proper destination if (!is_dir($destination)) { mkdir($destination, 0777); } // save image switch ($type) { case 1: case 2: imagejpeg($thumb, $destination. '/' .$filename); break; case 3: imagepng($thumb, $destination. '/' .$filename); break; } // memory saving imagedestroy($thumb); imagedestroy($source); // thumbnail created successfully return TRUE; } /** * make the table to show the directories and photos */ function make_table ($list, $type, $row = 3) { // initialize gallery html array $gallery_html = array(); // check if we have a list > 0 if ($size = sizeof($list)) { switch ($type) { case "GALLERIES" : $gallery_html[] = '<div id="galleries">'; break; case "PHOTOS" : case "RAW" : $gallery_html[] = '<div id="photos">'; break; } // loop through list for ($i = 0; $i < sizeof($list); $i++) { // shall we open a new list if ($i % $row == 0) { $gallery_html[] = '<ul>'; } // add to list switch ($type) { case "GALLERIES" : // create the delete link $delete_link = ''; if ($_SESSION['logged_in']) { $delete_link = '[ <a href="admin.php?mode=deletealbum&a=' .$list[$i]['album_id']. '">Delete</a> ]'; } $gallery_html[] = '<a href=portfolio.php?albums='.$list[$i]['album_id'].'><img src="folder.gif" class="directory"><br />' .addslashes($list[$i]['album_name']). '</a><br />' .$delete_link. '</li>'; break; case "PHOTOS" : // construct photo name $name = $list[$i]['photo_proper']; // construct location $location = "photos/"; // create thumbnail if (!file_exists($location. "/thumbs/" .$name)) { thumbnail($name, $location. "/" .$name, $location. "/thumbs/"); } // construct date $date = '<div class="date">' .date("d/m G:ia", $list[$i]['photo_date']). '</div>'; // create the delete link $delete_link = ''; if ($_SESSION['logged_in']) { $delete_link = '[ <a href="admin.php?mode=deletephoto&p=' .$list[$i]['photo_id']. '">Delete</a> ]'; } // image information list($width, $height) = getimagesize($location . $list[$i]['photo_proper']); // add to the html $gallery_html[] = '<li><a href="' .$location . $list[$i]['photo_proper']. '" rel="lightbox[racing]" title="Photos"><img src="' .$location. "/thumbs/" .$name. '" class="picture"><br />View</a><br />' .$delete_link. '</li>'; break; case "RAW" : $gallery_html[] = '<li><img src="' .$list[$i]. '" class="picture"></li>'; break; } // shall we close the list if ( ($i + 1) % $row === 0 || ($i + 1) == $size) { $gallery_html[] = '</ul>'; } } $gallery_html[] = '</div>'; } return implode('', $gallery_html); } ?> Ok I am designing a php upload that will take a image file from a form and change the name of the file to the productnumber also recieved from the form. I had it working the otherday now it says Warning: copy() [function.copy]: open_basedir restriction in effect File() is not within the allowed path(s): (/home:/tmp:/usr) addpro.php on line 51. my files are attached.... note that $pnum is the product number gotten from my form and image is the image being uploaded gotten from the form also. The thing is it worked the other day but now it don't is it a change to the server ( I dont run the server) or did I mess up my code since then? I really need a code that will do this two time over once for a small image being put into a folder called small and once for a folder called large both images being uploaded and being changed to $pnum.ext so they will both be displayed when being called out by the product number. but I can work on that after I get this one working. line 51 is $copied = copy($_FILES['image']['tmp_name'], $newname); I came across the PHP clone method. Does this clone first level fields and methods or does it also do deep copying e.g. copying references to those fields. For example, a field may be an array. Does it make a copy of the actual array or does it refer to the same array position in memory, so if the original changes, then the copy's changes as well?
This was generated through phpFormGenerator, but I'm getting the following warning message when a file is not uploaded. I didn't set it as a required field. "Warning: copy() [function.copy]: Filename cannot be empty ..." If it possible to skip this check since it's not supposed to be required to upload a file? I'm simply trying to make a contact form that emails basic information with the added option of attaching a file/picture. Code: [Select] <?php include("global.inc.php"); $errors=0; $error="The following errors occured while processing your form input.<ul>"; pt_register('POST','FullName'); pt_register('POST','Email'); pt_register('POST','Phone'); pt_register('POST','QuestionsorComments'); $QuestionsorComments=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $QuestionsorComments);$AttachPictureforQuote=$HTTP_POST_FILES['AttachPictureforQuote']; pt_register('POST','Howdidyoufindus'); if($FullName=="" || $Email=="" ){ $errors=1; $error.="<li>You did not enter one or more of the required fields. Please go back and try again."; } if($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name']==""){ } else if(!is_uploaded_file($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name'])){ $error.="<li>The file, ".$HTTP_POST_FILES['AttachPictureforQuote']['name'].", was not uploaded!"; $errors=1; } if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){ $error.="<li>Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $image_part = date("h_i_s")."_".$HTTP_POST_FILES['AttachPictureforQuote']['name']; $image_list[4] = $image_part; copy($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name'], "files/".$image_part); $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/")); $message="Full Name: ".$FullName." Email: ".$Email." Phone: ".$Phone." Questions or Comments: ".$QuestionsorComments." Attach Picture for Quote: ".$where_form_is."files/".$image_list[4]." How did you find us: ".$Howdidyoufindus." "; $message = stripslashes($message); mail("webmaster@gmail.com","Form Submitted at your website",$message,"From: phpFormGenerator"); ?> <!-- This is the content of the Thank you page, be careful while changing it --> <h2>Thank you!</h2> <table width=50%> <tr><td>Full Name: </td><td> <?php echo $FullName; ?> </td></tr> <tr><td>Email: </td><td> <?php echo $Email; ?> </td></tr> <tr><td>Phone: </td><td> <?php echo $Phone; ?> </td></tr> <tr><td>Questions or Comments: </td><td> <?php echo $QuestionsorComments; ?> </td></tr> <tr><td>Attach Picture for Quote: </td><td> <?php echo $AttachPictureforQuote; ?> </td></tr> <tr><td>How did you find us: </td><td> <?php echo $Howdidyoufindus; ?> </td></tr> </table> <!-- Do not change anything below this line --> <?php } ?> Thanks for your time and any help you can provide! Hi, I've read a lot of places that it's not recommended to store binary files in my db. So instead I'm supposed to upload the image to a directory, and store the link to that directory in database. First, how would I make a form that uploads the picture to the directory (And what kinda directories are we talking?). Secondly, how would I retrieve that link? And I guess I should rename the picture.. I'd appreciate any help, or a good tutorial (Haven't found any myself). How can i edit just one image at on time with a multiple image upload form? I have the images being stored in a folder and the path being stored in MySQL. I also have the files being uploaded with a unique id. My issue is that I want to be able to pass the values of what is already in $name2 $name3 $name4 if I only want to edit $name1. I don't want to have to manually update the 4 images. Here is the PHP: Code: [Select] <?php require_once('storescripts/connect.php'); mysql_select_db($database_phpimage,$phpimage); $uploadDir = 'upload/'; if(isset($_POST['upload'])) { foreach ($_FILES as $file) { $fileName = $file['name']; $tmpName = $file['tmp_name']; $fileSize = $file['size']; $fileType = $file['type']; if ($fileName != ""){ $filePath = $uploadDir; $fileName = str_replace(" ", "_", $fileName); //Split the name into the base name and extension $pathInfo = pathinfo($fileName); $fileName_base = $pathInfo['fileName']; $fileName_ext = $pathInfo['extension']; //now we re-assemble the file name, sticking the output of uniqid into it //and keep doing this in a loop until we generate a name that //does not already exist (most likely we will get that first try) do { $fileName = $fileName_base . uniqid() . '.' . $fileName_ext; } while (file_exists($filePath.$fileName)); $file_names [] = $fileName; $result = move_uploaded_file($tmpName, $filePath.$fileName); } if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $fileinsert[] = $filePath; } } $mid = mysql_real_escape_string(trim($_POST['mid'])); $cat = mysql_real_escape_string(trim($_POST['cat'])); $item = mysql_real_escape_string(trim($_POST['item'])); $price = mysql_real_escape_string(trim($_POST['price'])); $about = mysql_real_escape_string(trim($_POST['about'])); $fields = array(); $values = array(); $updateVals = array(); for($i = 0; $i < 4; $i++) { $values[$i] = isset($file_names[$i]) ? mysql_real_escape_string($file_names[$i]) : ''; if($values[$i] != '') { $updateVals[] = 'name' . ($i + 1) . " = '{$values[$i]}'"; } } $updateNames = ''; if(count($updateVals)) { $updateNames = ", " . implode(', ', $updateVals); } $update = "INSERT INTO image (mid, cid, item, price, about, name1, name2, name3, name4) VALUES ('$mid', '$cat', '$item', '$price', '$about', '$values[0]', '$values[1]', '$values[2]', '$values[3]') ON DUPLICATE KEY UPDATE cid = '$cat', item = '$item', price = '$price', about = '$about' $updateNames"; $result = mysql_query($update) or die (mysql_error()); Can I get some help or a point in the right direction.
I am trying to create a form that allows me to add, edit and delete records from a database.
I can add, edit and delete if I dont include the image upload code.
If I include the upload code I cant edit records without having to upload the the same image to make the record save to the database.
So I can tell I have got the code processing in the wrong way, thing is I cant seem to see or grasp the flow of this, to make the corrections I need it work.
Any help would be great!
Here is the form add.php code
<?php require_once ("dbconnection.php"); $id=""; $venue_name=""; $address=""; $city=""; $post_code=""; $country_code=""; $url=""; $email=""; $description=""; $img_url=""; $tags=""; if(isset($_GET['id'])){ $id = $_GET['id']; $sqlLoader="Select from venue where id=?"; $resLoader=$db->prepare($sqlLoader); $resLoader->execute(array($id)); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Add Venue Page</title> <link href='http://fonts.googleapis.com/css?family=Droid+Sans' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <?php $sqladd="Select * from venue where id=?"; $resadd=$db->prepare($sqladd); $resadd->execute(array($id)); while($rowadd = $resadd->fetch(PDO::FETCH_ASSOC)){ $v_id=$rowadd['id']; $venue_name=$rowadd['venue_name']; $address=$rowadd['address']; $city=$rowadd['city']; $post_code=$rowadd['post_code']; $country_code=$rowadd['country_code']; $url=$rowadd['url']; $email=$rowadd['email']; $description=$rowadd['description']; $img_url=$rowadd['img_url']; $tags=$rowadd['tags']; } ?> <h1 class="edit-venue-title">Add Venue:</h1> <form role="form" enctype="multipart/form-data" method="post" name="formVenue" action="save.php"> <input type="hidden" name="id" value="<?php echo $id; ?>"/> <div class="form-group"> <input class="form-control" type="hidden" name="id" value="<?php echo $id; ?>"/> <p><strong>ID:</strong> <?php echo $id; ?></p> <strong>Venue Name: *</strong> <input class="form-control" type="text" name="venue_name" value="<?php echo $venue_name; ?>"/><br/> <br/> <strong>Address: *</strong> <input class="form-control" type="text" name="address" value="<?php echo $address; ?>"/><br/> <br/> <strong>City: *</strong> <input class="form-control" type="text" name="city" value="<?php echo $city; ?>"/><br/> <br/> <strong>Post Code: *</strong> <input class="form-control" type="text" name="post_code" value="<?php echo $post_code; ?>"/><br/> <br/> <strong>Country Code: *</strong> <input class="form-control" type="text" name="country_code" value="<?php echo $country_code; ?>"/><br/> <br/> <strong>URL: *</strong> <input class="form-control" type="text" name="url" value="<?php echo $url; ?>"/><br/> <br/> <strong>Email: *</strong> <input class="form-control" type="email" name="email" value="<?php echo $email; ?>"/><br/> <br/> <strong>Description: *</strong> <textarea class="form-control" type="text" name="description" rows ="7" value=""><?php echo $description; ?></textarea><br/> <br/> <strong>Image Upload: *</strong> <input class="form-control" type="file" name="image" value="<?php echo $img_url; ?>"/> <small>File sizes 300kb's and below 500px height and width.<br/><strong>Image is required or data will not save.</strong></small> <br/><br/> <strong>Tags: *</strong> <input class="form-control" type="text" name="tags" value="<?php echo $tags; ?>"/><small>comma seperated vales only, e.g. soul,hip-hop,reggae</small><br/> <br/> <p>* Required</p> <br/> <input class="btn btn-primary" type="submit" name="submit" value="Save"> </div> </form> </div> </body> </html>Here is the save.php code <?php error_reporting(E_ALL); ini_set("display_errors", 1); include ("dbconnection.php"); $venue_name=$_POST['venue_name']; $address=$_POST['address']; $city=$_POST['city']; $post_code=$_POST['post_code']; $country_code=$_POST['country_code']; $url=$_POST['url']; $email=$_POST['email']; $description=$_POST['description']; $tags=$_POST['tags']; $id=$_POST['id']; if(is_uploaded_file($_FILES['image']['tmp_name'])){ $folder = "images/hs-venues/"; $file = basename( $_FILES['image']['name']); $full_path = $folder.$file; if(move_uploaded_file($_FILES['image']['tmp_name'], $full_path)) { //echo "succesful upload, we have an image!"; var_dump($_POST); if($id==null){ $sql="INSERT INTO venue(venue_name,address,city,post_code,country_code,url,email,description,img_url,tags)values(:venue_name,:address,:city,:post_code,:country_code,:url,:email,:description,:img_url,:tags)"; $qry=$db->prepare($sql); $qry->execute(array(':venue_name'=>$venue_name,':address'=>$address,':city'=>$city,':post_code'=>$post_code,':country_code'=>$country_code,':url'=>$url,':email'=>$email,':description'=>$description,':img_url'=>$full_path,':tags'=>$tags)); }else{ $sql="UPDATE venue SET venue_name=?, address=?, city=?, post_code=?, country_code=?, url=?, email=?, description=?, img_url=?, tags=? where id=?"; $qry=$db->prepare($sql); $qry->execute(array($venue_name, $address, $city, $post_code, $country_code, $url, $email, $description, $full_path, $tags, $id)); } if($success){ var_dump($_POST); echo "<script language='javascript' type='text/javascript'>alert('Successfully Saved!')</script>"; echo "<script language='javascript' type='text/javascript'>window.open('index.php','_self')</script>"; } else{ var_dump($_POST); echo "<script language='javascript' type='text/javascript'>alert('Successfully Saved!')</script>"; echo "<script language='javascript' type='text/javascript'>window.open('index.php','_self')</script>"; } } //if uploaded else{ var_dump($_POST); echo "<script language='javascript' type='text/javascript'>alert('Upload Recieved but Processed Failed!')</script>"; echo "<script language='javascript' type='text/javascript'>window.open('index.php','_self')</script>"; } } //move uploaded else{ var_dump($_POST); echo "<script language='javascript' type='text/javascript'>alert('Successfully Updated.')</script>"; echo "<script language='javascript' type='text/javascript'>window.open('index.php','_self')</script>"; } ?>Thanks in advance! Edited by hankmoody, 12 August 2014 - 05:15 PM. Hello, I've had success creating a cool vanity QR code with rounded edges for my organization by generating a standard QR code, then applying a noise -> median effect in Photoshop to get the edges rounded among some other effects. Photoshop is great, but I want to automate this. I found a great PHP library to generate QR codes. The part I don't get is the rounding of the hard edges. I've seen other sites do it like this one. So far google searches are yielding rounded corner tutorials. Any thoughts on how to do this with GD or ImageMagic? Best regards, Chris Hello I am having problems uploading an image through a HTML form. I want the image to be uploaded to the server and the image name to be written to the mysql database. Below is the code I am using: Code: [Select] <?php if (isset($_POST['add'])){ echo "<br /> add value is true"; $name = $_POST['name']; $description = $_POST['description']; $price = $_POST['price']; $category_id = $_POST['category_name']; $image = $_FILES['image']['name']; //file path of the image upload $filepath = "../images/"; //mew name for the image upload $newimagename = $name; //new width for the image $newwidth = 100; //new height for the image $newheight = 100; include('../includes/image-upload.php'); mysql_query("INSERT INTO item (item_name, item_description, item_price, item_image) VALUES ('$name','$description','$price','$image')"); ?> Here is the image-upload.php file code: Code: [Select] <?php //assigns the file to the image $image =$_FILES["image"]["name"]; $uploadedfile =$_FILES["image"]["tmp_name"]; if ($image) { //retrieves the extension type from image upload $extension = getextension($image); //converts extension to lowercase $extension = strtolower($extension); //create image from uploaded file type if($extension=="jpg" || $extension=="jpeg") { $uploadedfile = $_FILES['image']['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); }else if($extension=="png") { $uploadedfile = $_FILES['image']['tmp_name']; $src = imagecreatefrompng($uploadedfile); }else{ $src = imagecreatefromgif($uploadedfile); } //creates a list of the width and height of the image list($width,$height)=getimagesize($uploadedfile); //adds color to the image $tmp = imagecreatetruecolor($newwidth,$newheight); //create image imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); //set file name $filename = $filepath.$newimagename.".".$extension; $imagename = $newimagename.".".$extension; //uploads new file with name to the chosen directory imagejpeg($tmp,$filename,100); //empty variables imagedestroy($src); imagedestroy($tmp); } ?> Any help would be appreciated, fairly new to all this! Thanks!!! This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=351137.0 Would like to be able to click on a radio button that represents an image. Once selected and submitted, have that image display on another page. I have an idea, but need some guidance. BTW, is using php only doable? Is there a simpler or more elegant way to do this? Thanks all! |