PHP - Moved: Modify Script?
This topic has been moved to Third Party PHP Scripts.
http://www.phpfreaks.com/forums/index.php?topic=334372.0 Similar TutorialsThis topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=310049.0 Hi i have this upload script which works fine it uploads image to a specified folder and sends the the details to the database. but now i am trying to instead make a modify script which is Update set so i tried to change insert to update but didnt work can someone help me out please this my insert image script which works fine but want to change to modify instead Code: [Select] <?php mysql_connect("localhost", "root", "") or die(mysql_error()) ; mysql_select_db("upload") or die(mysql_error()) ; // my file the name of the input area on the form type is the extension of the file //echo $_FILES["myfile"]["type"]; //myfile is the name of the input area on the form $name = $_FILES["image"] ["name"]; // name of the file $type = $_FILES["image"]["type"]; //type of the file $size = $_FILES["image"]["size"]; //the size of the file $temp = $_FILES["image"]["tmp_name"];//temporary file location when click upload it temporary stores on the computer and gives it a temporary name $error =array(); // this an empty array where you can then call on all of the error messages $allowed_exts = array('jpg', 'jpeg', 'png', 'gif'); // array with the following extension name values $image_type = array('image/jpg', 'image/jpeg', 'image/png', 'image/gif'); // array with the following image type values $location = 'images/'; //location of the file or directory where the file will be stored $appendic_name = "news".$name;//this append the word [news] before the name so the image would be news[nameofimage].gif // substr counts the number of carachters and then you the specify how how many you letters you want to cut off from the beginning of the word example drivers.jpg it would cut off dri, and would display vers.jpg //echo $extension = substr($name, 3); //using both substr and strpos, strpos it will delete anything before the dot in this case it finds the dot on the $name file deletes and + 1 says read after the last letter you delete because you want to display the letters after the dot. if remove the +1 it will display .gif which what we want is just gif $extension = strtolower(substr($name, strpos ($name, '.') +1));//strlower turn the extension non capital in case extension is capital example JPG will strtolower will make jpg // another way of doing is with explode // $image_ext strtolower(end(explode('.',$name))); will explode from where you want in this case from the dot adn end will display from the end after the explode $myfile = $_POST["myfile"]; if (isset($image)) // if you choose a file name do the if bellow { // if extension is not equal to any of the variables in the array $allowed_exts error appears if(in_array($extension, $allowed_exts) === false ) { $error[] = 'Extension not allowed! gif, jpg, jpeg, png only<br />'; // if no errror read next if line } // if file type is not equal to any of the variables in array $image_type error appears if(in_array($type, $image_type) === false) { $error[] = 'Type of file not allowed! only images allowed<br />'; } // if file bigger than the number bellow error message if($size > 2097152) { $error[] = 'File size must be under 2MB!'; } // check if folder exist in the server if(!file_exists ($location)) { $error[] = 'No directory ' . $location. ' on the server Please create a folder ' .$location; } } // if no error found do the move upload function if (empty($error)){ if (move_uploaded_file($temp, $location .$appendic_name)) { // insert data into database first are the field name teh values are the variables you want to insert into those fields appendic is the new name of the image mysql_query("INSERT INTO image (myfile ,image) VALUES ('$myfile', '$appendic_name')") ; exit(); } } else { foreach ($error as $error) { echo $error; } } //echo $type; ?> For right or wrong, I've been using XML to define my Doctrine entities. When the XML changes, my entities need to change. I've automated the process with a simple PHP script which allows me to swap some text to modify one of the auto-generated methods, add methods, etc. Kind of clunky but it works well enough. Now, I recently had the need to remove a given method in its entirety from a given class. I "could" just add the entire string which represents the method name, earlier comments, and script for the method to my parsing script to my parsing script and remove it, but would like to be a little more concise. For instance, say I have $script as follows: $script = <<<'EOT' class SomeEntityClass { //... more stuff above public function getSomething() { return $this->something; } /** * Get foos. * * @return \Doctrine\Common\Collections\Collection */ public function getFoos() { return $this->foos; } /** * Get somethingElse. * */ //... more stuff below } EOT; How would you recommend creating the function: removeFunction($script, 'getFoos') which would remove the given function along with its comments from the $script string and result with? $script = <<<'EOT' class SomeEntityClass { //... more stuff above public function getSomething() { return $this->something; } /** * Get somethingElse. * */ //... more stuff below } EOT; Assuming regex is the way to go, I was thinking of something like the following, but could use some help with the regex expression. function removeFunction($script, $method) { $method="public function $method("; //regex to remove script with which starts after pattern "{\n" OR "**/", contains $method, and is located before pattern "\n{" OR "\n /**" return $script; } Thanks i have this awesome script i've used on multiple websites and only now is it giving me trouble. it's always aligned/cropped to the middle of the image but for some reason the smaller thumbnails are cropping to the bottom. Code: [Select] <?php header ("Content-type: image/jpeg"); $file_name=$_GET['f']; $crop_height=$_GET['h']; $crop_width=$_GET['w']; $file_type= explode('.', $file_name); $file_type = $file_type[count($file_type) -1]; $file_type=strtolower($file_type); $original_image_size = getimagesize($file_name); $original_width = $original_image_size[0]; $original_height = $original_image_size[0]; if($file_type=='jpg') { $original_image_gd = imagecreatefromjpeg($file_name); } if($file_type=='gif') { $original_image_gd = imagecreatefromgif($file_name); } if($file_type=='png') { $original_image_gd = imagecreatefrompng($file_name); } $cropped_image_gd = imagecreatetruecolor($crop_width, $crop_height); $wm = $original_width /$crop_width; $hm = $original_height /$crop_height; $h_height = $crop_height/2; $w_height = $crop_width/2; if($original_width > $original_height ) { $adjusted_width =$original_width / $hm; $half_width = $adjusted_width / 2; $int_width = $half_width - $w_height; imagecopyresampled($cropped_image_gd ,$original_image_gd ,-$int_width,0,0,0, $adjusted_width, $crop_height, $original_width , $original_height ); } elseif(($original_width < $original_height ) || ($original_width == $original_height )) { $adjusted_height = $original_height / $wm; $half_height = $adjusted_height / 2; $int_height = $half_height - $h_height; imagecopyresampled($cropped_image_gd , $original_image_gd ,0,-$int_height,0,0, $crop_width, $adjusted_height, $original_width , $original_height ); } else { imagecopyresampled($cropped_image_gd , $original_image_gd ,0,0,0,0, $crop_width, $crop_height, $original_width , $original_height ); } imagejpeg($cropped_image_gd); ?> if i modify the value of original_image_size, it crops to the middle, but if the height is greater than the width it will add black on either side of the image to fill out the designated value. Code: [Select] $original_image_size = getimagesize($file_name); $original_width = $original_image_size[0]; $original_height = $original_image_size[1]; i can't figure out how to get it do both. 0, 0 outputs this: http://www.loudtechinc.com/images/scriptissue/00.png http://www.loudtechinc.com/images/scriptissue/00n2.png 0, 1 outputs this: http://www.loudtechinc.com/images/scriptissue/01.png http://www.loudtechinc.com/images/scriptissue/01n2.png The end goal is to have it fill the desired height and width while cropping to the middle. This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=348869.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=307535.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=321105.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342772.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=343070.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=320494.0 This topic has been moved to Beta Test Your Stuff!. http://www.phpfreaks.com/forums/index.php?topic=352359.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=322839.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=314681.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=313684.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319561.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=322742.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=318755.0 This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=343605.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342897.0 This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=346654.0 |