PHP - Can't Get Image Resizer To Work Properly - It's Almost There!
I'm able to get the image file name in the database, the image to the right place BUT the problem is the image is totally black and after it's uploaded, a whole bunch of warnings appear. Here are the warnings:
Warning: getimagesize(image_files/image-16.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:\Desktop\xampp\htdocs\image-crop-demo.php on line 37 Warning: Division by zero in C:\Desktop\xampp\htdocs\image-crop-demo.php on line 54 Warning: Division by zero in C:\Users\Samantha\Desktop\xampp\htdocs\image-crop-demo.php on line 71 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Desktop\xampp\htdocs\image-crop-demo.php on line 78 Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in C:\Desktop\xampp\htdocs\image-crop-demo.php on line 86 Warning: imagecopy() expects parameter 2 to be resource, boolean given in C:\Desktop\xampp\htdocs\image-crop-demo.php on line 102 Here is the form: <form action="image-crop-demo.php?username=<?php echo $username ?>" method="post" enctype="multipart/form-data"> Upload an image for processing<br> <input type="file" name="Image1"><br> <input type="submit" value="Upload"> </form> And here is the form action file: $username = $_GET['username']; define( 'DESIRED_IMAGE_WIDTH', 150 ); define( 'DESIRED_IMAGE_HEIGHT', 150 ); $source_path = $_FILES[ 'Image1' ][ 'name' ]; $sql="UPDATE thumbnail SET Image1='$source_path' WHERE username = '$username'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } else { // // 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 $remote_file = "image_files/".$_FILES["Image1"]["name"]; imagejpeg($desired_gdim,$remote_file); }// Similar TutorialsI already have a script that uploads the image but I would like to make a copy of the image resized down by 50% and uploaded to a new folder (imgups/thumbnails) I want it to do this all in one php script. I am not sure how to do this. 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"] ); why aint this working?? Code: [Select] <?php if ($_COOKIE['watch_id']){ $cookie = $_COOKIE['watch_id']; $cookie_query = mysql_query("SELECT * FROM user WHERE cookie='$cookie'"); if (mysql_num_rows($cookie_query) >= 1){ ?> <li><a href="/index.php">Home</a></li> <li><a href="/cpanel.php">C-Panel</a></li> <li><a href="/logout.php">Logout</a></li> pass <?php } if (mysql_num_rows($cookie_query) <= 1){ ?> <li><a href="register.php">Register</a></li> <li><a href="#" onclick="OPEN_login();">Login</a></li> <li><a href="index.php">Home</a></li> fail1 <?php } } if(!$_COOKIE['watch_id']){ ?> <li><a href="register.php">Register</a></li> <li><a href="#" onclick="OPEN_login();">Login</a></li> <li><a href="/index.php">Home</a></li> fail2 <?php } ?> i have checked in the browser and the cookies match but it always echos fail2 which means that this line is returning false: Code: [Select] if ($_COOKIE['watch_id']){ i have tried using isset but that didnt help either! any help? For the life of me, I cannot get an uploaded file to move from the tmp folder to the uploads folder. I have made sure all permissions were set to allow for the transfer. $upfile points to the right folder and file. print_r($_FILES); yields the following: Array ( [userfile] => Array ( [name] => 02.jpg [type] => image/jpeg [tmp_name] => /tmp/phpClFyXP [error] => 0 [size] => 121200 ) ) Any help would be greatly appreciated. HTML: Code: [Select] <html> <head></head> <body> <form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value = "2000000000"> Upload this file: <input name ="userfile" type="file"> <input type="submit" value="Send File"> </form> </body> </html> PHP: <html> <head> <title>Uploading...</title> </head> <body> <h1>Uploading file...</h1> <?php if ($_FILES['userfile']['error'] > 0) { echo 'Problem: '; switch ($_FILES['userfile']['error']) { case 1: echo 'File exceeded upload_max_filesize'; break; case 2: echo 'File exceeded max_file_size'; break; case 3: echo 'File only partially uploaded'; break; case 4: echo 'No file uploaded'; break; } exit; } // Does the file have the right MIME type? // put the file where we'd like it $upfile = '/timporn/uploads/'.$_FILES['userfile']['name']; echo $upfile; if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile)) { echo '<br>Problem: Could not move file to destination directory'; exit; } } else { echo 'Problem: Possible file upload attack. Filename: '; echo $_FILES['userfile']['name']; exit; } echo 'File uploaded successfully<br><br>'; // reformat the file contents $fp = fopen($upfile, 'r'); $contents = fread ($fp, filesize ($upfile)); fclose ($fp); $contents = strip_tags($contents); $fp = fopen($upfile, 'w'); fwrite($fp, $contents); fclose($fp); // show what was uploaded echo 'Preview of uploaded file contents:<br><hr>'; echo $contents; echo '<br><hr>'; ?> </body> </html> Hi guys, I have stuck with this issue for over 3 hours now. My remove all button just wouldn't work.
Can anyone tell me what's the issue? I have 2 pages, one parent and another pop-up page that takes the values (cartSubmit) from parent. And I wrote out the code for both pages but I just cannot get it to work.
I apologize in advanced if my code looks messy or doesn't make any sense.
Please take a look at the code and let me know if you could spot anything wrong with it. Any help is greatly appreciated.
Here is the code related to the remove all button in the parent page:
if(isset($_POST['finalSelected'])) { echo "<br/>inside"; if(!empty($_POST['fSelected'])) { echo "<br/>if NOT empty"; $chosen = $_POST['fSelected']; foreach ($chosen as $item) echo "</br>aID selected: $item </br>"; //implode function to transform an array to a string //chosen(array) to $delimit(String) $delimitStr = implode(", ", $chosen); //Save the selected String to SESSION if(!isset($_SESSION["final"])) { $_SESSION["final"] .= "$delimitStr"; } else { $_SESSION["final"] .= ", $delimitStr"; } //Explode function to transform the SESSION variable back to an array for further trimming. $arraySession = explode(', ', $_SESSION["final"]); //Array unique to filter out duplicates. $uniqueArray = array_unique($arraySession); $cartSubmit = implode(", ",$uniqueArray); $_SESSION['cartSubmit'] = $cartSubmit; } else { echo "<br/>else empty"; $noSubmit = $_SESSION["final"]; //Explode function to transform the SESSION variable back to an array for further trimming. $arraySession = explode(', ', $_SESSION["final"]); //Array unique to filter out duplicates. $uniqueArray = array_unique($arraySession); $cartSubmit = implode(", ",$uniqueArray); $_SESSION['cartSubmit'] = $cartSubmit; } } <form name= "finalForm" method="POST" action="test6-1.php" target = "_self"> <input type="Submit" name="finalSelected"/> <a href="javascript:popup('test6-3.php?aID= <?php if(empty($_SESSION['final']) && empty($_SESSION['cartSubmit'])) echo "0"; else if(empty($cartSubmit)) echo "0"; else echo $_SESSION['cartSubmit'];?>')">Cart</a> <?php if(isset($FinalName)) { foreach($FinalName as $key => $item) {?> <tr><td> <input type="checkbox" name="fSelected[]" value="<?php echo htmlspecialchars($FinalID[$key])?>" /> <?php echo "$FinalID[$key] & $item";?> </td></tr> <?php } }?> </form>And here is the code in the pop-up page. <script> window.onunload = refreshParent; function refreshParent() { window.opener.location.reload(); } </script> if(isset($_POST['removeAll'])) { $aID = "0"; unset($_SESSION['cartSubmit']); unset($_SESSION['final']); header("Location : test6-3.php?aID=0"); } Edited by Cyjm1120, 18 November 2014 - 12:16 PM. I cannot get my script to update table: locations_all column city_state to the full state name.. Here's what I've been hacking at for 4.5 hours now! Ready to hit the sack.. Thanks for any input: $state_list = array('AL' => "Alabama", 'AK' => "Alaska", 'AZ' => "Arizona", 'AR' => "Arkansas", 'CA' => "California", 'CO' => "Colorado", 'CT' => "Connecticut", 'DE' => "Delaware", 'DC' => "District Of Columbia", 'FL' => "Florida", 'GA' => "Georgia", 'HI' => "Hawaii", 'ID' => "Idaho", 'IL' => "Illinois", 'IN' => "Indiana", 'IA' => "Iowa", 'KS' => "Kansas", 'KY' => "Kentucky", 'LA' => "Louisiana", 'ME' => "Maine", 'MD' => "Maryland", 'MA' => "Massachusetts", 'MI' => "Michigan", 'MN' => "Minnesota", 'MS' => "Mississippi", 'MO' => "Missouri", 'MT' => "Montana", 'NE' => "Nebraska", 'NV' => "Nevada", 'NH' => "New Hampshire", 'NJ' => "New Jersey", 'NM' => "New Mexico", 'NY' => "New York", 'NC' => "North Carolina", 'ND' => "North Dakota", 'OH' => "Ohio", 'OK' => "Oklahoma", 'OR' => "Oregon", 'PA' => "Pennsylvania", 'RI' => "Rhode Island", 'SC' => "South Carolina", 'SD' => "South Dakota", 'TN' => "Tennessee", 'TX' => "Texas", 'UT' => "Utah", 'VT' => "Vermont", 'VA' => "Virginia", 'WA' => "Washington", 'WV' => "West Virginia", 'WI' => "Wisconsin", 'WY' => "Wyoming"); foreach ($state_list as $key => $value) { // get all state abbr and name values. while ($row = mysqli_fetch_array($result)) { $query2 = "UPDATE locations_all SET city_state=$value WHERE city_state=$key"; $result2 = mysqli_query($cxn, $query2) or die("MySQL error: " . mysqli_error($cxn) . "<hr>\nQuery: $query2"); } //while ($row = mysqli_fetch_array($result)) } //foreach ($state_list as $key => $value) Hello,
I have one search form and when I search something the result is whole records from the database not only the search term. Any help is appreciated. I will post only the part where is calculating the rows from db but if need I will post whole pagination script.
$searchTerm = trim($_POST['term']); $adjacents = 3; $sql1 = mysql_query("SELECT * FROM images ORDER BY id ASC"); $nr = mysql_num_rows($sql1); $limit = 6; $targetpage = "search.php"; $page = $_GET['page']; if($page) $start = ($page - 1) * $limit; else $start = 0; if ($page == 0) $page = 1; $prev = $page - 1; // $prev = $page - 1 $next = $page + 1; // $next = $page + 1 $lastpage = ceil($nr/$limit); //lastpage = total pages / items per page. $lpm1 = $lastpage - 1; $pagination = ""; .... .... // pagination ... ... // while loop for the results $sql = "SELECT id, name, caption FROM images WHERE caption LIKE '%".$searchTerm."%' ORDER BY id DESC LIMIT $start, $limit"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { $output.= "<div class=\"container_image\">"; $output.= "<a href=\"/pic-".$row['id'].".html\"><img src=\"/upload/".$row['name']."\" width=\"210\" height=\"150\"/></a>"; $output.= "</div>"; } Edited by vinsb, 21 July 2014 - 06:58 AM. I am currently creating a multi-user login system, and I have created the database in MySQL, but the problem is that my PHP script is not working as expected. I would like it so that if the user enters in a correct username + password combination, then they are redirected to a webpage called "congrats.php" for example. However, with my current PHP code, if I include a redirection instruction based on the correct input, then when I run the script, then the user is instantly taken to the congrats.php page without filling in any login details. I'm quite sure that the database has been connected to, as due to the layout of my script at the moment, the text that reads "You did it!" appears 4 times, the same number of rows in my MySQL database. My PHP coding for this is: Code: [Select] <html><head><title>Multi-User Log In Form</title></head> <body> <?php $self = $_SERVER['PHP_SELF']; $username = $_POST['username']; $password = $_POST['password']; ?> <form action = "<?php echo $self; ?>" method = "post"> Username <input type = "text" name = "username" size = "8"> Password <input type = "password" name = "password" size = "8"> <input type = "submit" value="Submit"> </form> <?php $conn = @mysql_connect("localhost", "root", "") or die ("Err: Conn"); $rs = @mysql_select_db("test3", $conn) or die ("Err: Db"); $sql = "select * from users"; $rs = mysql_query($sql, $conn); while ($row = mysql_fetch_array($rs)) { $name = $row["uname"]; $pass = $row["pword"]; if ($username = $name && $password = $pass) { //CODE FOR REDIRECTION SHOULD GO HERE //header("location:congrats.php"); echo "You did it!"; } else { echo "Invalid username and password combination"; } } ?></body> </html> Any help in trying to get it so that my PHP script will redirect only if a correct username + password combination is entered would be greatly appreciated HI, according to my knowledge session_destroy() function would destroy all session variables and mysql_close() would close connection with the database. i make a simply logoff.php file and close myssql connection and destroy session. but i still get values from the database and session variables. and doesnt work properly here is the code Code: [Select] <?php session_start(); /* * To change this template, choose Tools | Templates * and open the template in the editor. */ require_once '../database/db_connecting.php'; $dbname="sahansevena";//set database name $con= setConnections();//make connections use implemented methode in db_connectiong.php mysql_select_db($dbname, $con); //update the time and date of the admin table $update_time="update admin set last_logged_date =CURDATE(), last_log_time=CURTIME() where username='$uname'limit 3,4"; //my admin table contain 5 colums they are id, username,password, last_logged_date, last_log_time $link= mysql_query($update_time); // mysql_select_db($dbname, $link); //$con=mysql_connect('localhost', 'root','ijts'); $result="select * from admin where username='a'"; $result=mysql_query($result); mysql_close($con); //here i just check after closing data baseconnection whether i do get reselts but i do, why? echo "after the cnnection was closed"; echo "<html>"; echo "<table border='1' cellspacing='1' cellpadding='2' align='center'>"; echo "<thead>"; echo"<tr>"; echo "<th>"; echo ID; echo"</th>"; echo" <th>";echo Username; echo"</th>"; echo"<th>";echo Password; echo"</th>"; echo"<th>";echo Last_logged_date; echo "</th>"; echo "<th>";echo Last_logged_time; echo "</th>"; echo" </tr>"; echo" </thead>"; echo" <tbody>"; while($row= mysql_fetch_array($result,MYSQL_BOTH)){ echo "<tr>"; echo "<td>"; echo $row[0]; echo "</td>"; echo "<td>"; echo $row[1]; echo "</td>"; echo "<td>"; echo $row[2]; echo "</td>"; echo "<td>"; echo $row[3]; echo "</td>"; echo "<td>"; echo $row[4]; echo "</td>"; echo "</tr>"; } echo" </tbody>"; echo "</table>"; echo "</html>"; session_destroy(); session_commit(); echo "session and database are closed but i still get values".$_SESSION['admin']; ?> Hi, I have three divs all with different z indexes. One div shows a clickable world map that goes to the monsters and background divs, which is set up in an array. The problem is, when the map is clicked, it doesn't go to the first element in the array, and when I go "back" with the back button, it doesn't go all the way to the map. Also, I want to link 2 image maps togather, and I don't know how to do it. any help GREATLY appreciated. Here is the relevant code. Code: [Select] /////////////////////////////GAME NAVIGATION AND MONSTER SEARCH CODE NOT FINISHED////////////////////////////////// $locations[0] = array(); $locations[1] = array( 'background_images' => array( "<img src='sundragon_environments/ocean/ocean1_FRAME.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME2.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME3.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME4.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME5.jpg'/>" ), 'monster_images' => array( "<img src='sundragon_monsters_source/water/goldfish/goldfish.png'/>", "<img src='sundragon_monsters_source/water/eel/eel_transp_FRAME.png '/>", "<img src='sundragon_monsters_source/water/shark/shark_transp_FRAME.png'/>", "<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>", "<img src='sundragon_monsters_source/water/teardrop_ocean_protector/teardrop_ocean_protector.png'/>" ) ); $locations[2] = array( 'background_images' => array( "<img src='sundragon_environments/shore/teardrop_shore/teardrop_shore1.jpg'/>", "<img src='sundragon_environments/shore/teardrop_shore/teardrop_shore2.jpg'/>", "<img src='sundragon_environments/shore/teardrop_shore/teardrop_shore3.jpg'/>", "<img src='sundragon_environments/shore/teardrop_shore/teardrop_shore4.jpg'/>", "<img src='sundragon_environments/shore/teardrop_shore/teardrop_shore5.jpg'/>" ), 'monster_images' => array( "<img src='sundragon_monsters_source/shore/teardrop_shore/cats/background1_cat.png'/>", "<img src='sundragon_monsters_source/shore/teardrop_shore/cats/background2_cat.png'/>", "<img src='sundragon_monsters_source/shore/teardrop_shore/cats/background3_cat.png'/>", "<img src='sundragon_monsters_source/shore/teardrop_shore/cats/background4_cat.png'/>", "<img src='sundragon_monsters_source/shore/teardrop_shore/cats/background5_cat.png'/>" ) ); $locations[3] = array( 'background_images' => array( "<img src='sundragon_environments/forest/whispering_forest/whispering_forest1.jpg'/>", "<img src='sundragon_environments/forest/whispering_forest/whispering_forest2.jpg'/>", "<img src='sundragon_environments/forest/whispering_forest/whispering_forest3.jpg'/>", "<img src='sundragon_environments/forest/whispering_forest/whispering_forest4.jpg'/>", "<img src='sundragon_environments/forest/whispering_forest/whispering_forest5.jpg'/>" ), 'monster_images' => array( "<img src='sundragon_monsters_source/forest/whispering_forest/whispering_monkey_1.png'/>", "<img src='sundragon_monsters_source/forest/whispering_forest/whispering_fairy_2.png'/>", "<img src='sundragon_monsters_source/forest/whispering_forest/giant_toad_3.png'/>", "<img src='sundragon_monsters_source/forest/whispering_forest/whispering_bear_4.png'/>", "<img src='sundragon_monsters_source/forest/whispering_forest/lizasaur_5.png'/>" ) ); 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. $echoMap = ' <img src="aradia.jpg" width="256" height="328" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="5,178,28,220" href="?newLocation=1" /> <area shape="rect" coords="6,224,43,254" href="?newLocation=2" /> <area shape="rect" coords="26,263,60,295" href="?newLocation=3" /> </map>'; $currentMonster = ''; } Code: [Select] <div id="monster_background"><?php echo $currentBackground;?></div> <div id="transparent_monster"><?php echo $currentMonster;?><?php echo $echoMap; ?></div> I'm having a really hard time getting my carousel to display in a line when I call my images from the table:
<div id="user-gallery"> <h2>Recent Images</h2> <button class="prev"><<</button> <button class="next">>></button> <?php include("file/image/upload_file.php"); $select_query = "SELECT `images_path` FROM `images_tbl` ORDER by `images_id` DESC LIMIT 9"; $sql = mysql_query($select_query) or die(mysql_error()); while($row = mysql_fetch_array($sql,MYSQL_BOTH)){ ?> <div class="anyClass"> <ul> <li><img src="<?php echo $row["images_path"]; ?>" alt="" width="125" height="70" ></li> <li><img src="<?php echo $row["images_path"]; ?>" alt="" width="125" height="70" ></li> <li><img src="<?php echo $row["images_path"]; ?>" alt="" width="125" height="70" ></li> <li><img src="<?php echo $row["images_path"]; ?>" alt="" width="125" height="70"></li> </ul> </div> <?php } ?> </div>Without the carousel it will display perfectly, but as soon as I implement it, the images won't behave normal :/ I tried to google it but i'm not quite sure how to formulate the proper phrase to express what i'm looking to do. What i'm trying to accomplish is cropping an image without chopping away any bits of the content within that image. For example, imagine you have a square image the size 1000px by 1000px canvas and within that canvas is a photo of an object that's roughly 400px BY 750px. I would like to crop the 1000x1000 canvas to be within 5 pixels of the longest side of the content image, so in this case i'd like to crop it to a 755x755 squared pixel image. So i guess the main question is how can i check for the content on a canvas which btw may not always be white, but might be other colors and of other things in the background. I understand some things may make it impossible, but let's just for now assume the canvas is always white. Thanks! Hello everyone! I'm working on a form that can upload an image on server and add the image name on mysql db. The add page works correctly, the image is uploaded correctly and the image name is inserted on the db. But, the edit page dows not work ... When i click on Send option on the edit page and i'm not adding any image, the image db field remains black, and, when i want to upload an image (change the image) via the edit page form, the image is not uploaded and the image db field remains blabk Can you help me please? add page <? include('header.php'); include ('includes/uploader.class.php'); $uploader = new uploader(); // Setting properties then Uploading the image $uploader->destDir = "D:/Program Files/VertrigoServ/www/oldi/imazhet/artikuj/"; $uploader->upload($_FILES['LajmeImg']); echo '<div class="majtas">'; // Remember any variables incase the form validation finds errors. $LajmeEmri = $_POST['LajmeEmri']; $KatLajmeID = $_POST['KatLajmeID']; // Kategoria Lajmeve $LajmeIntro = $_POST['LajmeIntro']; $LajmeTxt = $_POST['LajmeTxt']; $LajmeAktiv = $_POST['LajmeAktiv']; $LajmeTag = $_POST['LajmeTag']; $LajmeVideo = $_POST['LajmeVideo']; //$LajmeImg = $_FILES['LajmeImg']['name']; // Me autoName = False; regjistron ne db emrin real te fotografise $LajmeImg = $uploader->source['name']; // Me autoName = true; regjistron ne db emrin random te fotografise i gjeneruar ne base64 $LajmeLink = preg_replace("#[^a-z0-9\-_]#i", "",str_replace(' ', '_', $LajmeEmri)); // Ben Url automatikisht nga titulli (LajmeEmri) i lajmit if(isset($_POST['add_lajme'])) { $LajmeEmri = $_POST['LajmeEmri']; $KatLajmeID = $_POST['KatLajmeID']; // Kategoria Lajmeve $LajmeIntro = $_POST['LajmeIntro']; $LajmeTxt = $_POST['LajmeTxt']; $LajmeAktiv = $_POST['LajmeAktiv']; $LajmeTag = $_POST['LajmeTag']; $LajmeVideo = $_POST['LajmeVideo']; //$LajmeImg = $_FILES['LajmeImg']['name']; // Me autoName = False; regjistron ne db emrin real te fotografise $LajmeImg = $uploader->source['name']; // Me autoName = true; regjistron ne db emrin random te fotografise i gjeneruar ne base64 $LajmeLink = preg_replace("#[^a-z0-9\-_]#i", "",str_replace(' ', '_', $LajmeEmri)); // Ben Url automatikisht nga titulli (LajmeEmri) i lajmit if(trim($KatLajmeID) == '0') { $error = '<div class="error_message">Attention! Nuk ke zgjedhur kategorine.</div>'; } else if(trim($LajmeIntro) == '') { $error = '<div class="error_message">Attention! Nuk ke vene Intro.</div>'; } else if(trim($LajmeEmri) == '') { $error = '<div class="error_message">Attention! Nuk ke vene emrin.</div>'; } $count = mysql_num_rows(mysql_query("SELECT * FROM lajme WHERE LajmeLink='".$LajmeLink."'")); if($count > 0) { $error = '<div class="error_message">Ky emer/url gjendet ne database.</div>'; } if($error == '') { $sql = "INSERT INTO lajme (KatLajmeID, LajmeEmri, LajmeLink, LajmeIntro, LajmeTxt, LajmeAktiv, LajmeTag, LajmeVideo, LajmeImg) VALUES ('$KatLajmeID', '$LajmeEmri', '$LajmeLink', '$LajmeIntro', '$LajmeTxt', '$LajmeAktiv', '$LajmeTag', '$LajmeVideo', '$LajmeImg')"; $query = mysql_query($sql) or die("Fatal error: ".mysql_error()); echo "<h2>Success!</h2>"; echo "<div class='success_message'>U Shtua me sukses lajmi <b>$LajmeEmri</b> ne kategorine <b>$KatLajmeID</b> .</div>"; echo "<h2>Te Dhenat e Lajmit</h2>"; echo "<ul class='success-reg'>"; echo "<li><span class='success-info'><b>Titulli</b></span>$LajmeEmri</li>"; echo "<li><span class='success-info'><b>Url</b></span>$LajmeLink</li>"; echo "<li><span class='success-info'><b>Kategoria</b></span>$KatLajmeID</li>"; echo "<li><span class='success-info'><b>Aktive</b></span>$LajmeAktiv</li>"; echo "</ul>"; echo "<h2>Cfare deshiron te besh tani?</h2><br />"; echo "Shko tek <a href='lajme_edit.php'>modifikimi i lajmeve</a>.</li>"; } } if(!isset($_POST['add_lajme']) || $error != '') { echo $error; ?> <h2>Shto Lajme</h2> <form action="" method="post" enctype="multipart/form-data"> <label style="width: 28%;" for="KatLajmeID">Kategoria</label> <select id="KatLajmeID" name="KatLajmeID" size="1"> <?php $query="SELECT * FROM lajme_kategori "; $result=mysql_query($query); $num = mysql_num_rows ($result); mysql_close(); ?> <option selected value="0">Perzgjidh Kategorine</option> <? if ($num > 0 ) { $i=0; while ($i < $num) { $LKatID = mysql_result($result,$i,"LKatID"); $LKatEmri = mysql_result($result,$i,"LKatEmri"); $LKatLink = mysql_result($result,$i,"LKatLink"); $LKatAktiv= mysql_result($result,$i,"LKatAktiv"); ?> <option value="<?php echo $LKatID ?>"><?php echo $LKatEmri ?></option> <?php ++$i; } } ?> </select> <script type="text/javascript"> function toggle_LajmeLink(LajmeID) { if (window.XMLHttpRequest) { http = new XMLHttpRequest(); } else if (window.ActiveXObject) { http = new ActiveXObject("Microsoft.XMLHTTP"); } handle = document.getElementById(LajmeID); var url = '../ajax.php?'; if(handle.value.length > 0) { var fullurl = url + 'do=check_LajmeEmri_exists&LajmeEmri=' + encodeURIComponent(handle.value); http.open("GET", fullurl, true); http.send(null); http.onreadystatechange = statechange_LajmeEmri; }else{ document.getElementById('LajmeEmri').className = ''; } } function statechange_LajmeEmri() { if (http.readyState == 4) { var xmlObj = http.responseXML; var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data; document.getElementById('LajmeEmri').className = html; } } </script> <label>Titulli</label><input type="text" name="LajmeEmri" value="<?=$LajmeEmri;?>" onchange="toggle_LajmeEmri('LajmeEmri')" width="70%" /><br /> <label>Intro</label><textarea id="LajmeIntro" name="LajmeIntro" value="<?=$LajmeIntro;?>"></textarea> <script type="text/javascript"> CKEDITOR.replace( 'LajmeIntro', { filebrowserBrowseUrl : 'includes/ckfinder/ckfinder.html', filebrowserImageBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Images', filebrowserFlashBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Flash', filebrowserUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files', filebrowserImageUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images', filebrowserFlashUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash' }); </script><br /> <label>Lajmi</label><textarea id="LajmeTxt" name="LajmeTxt" value="<?=$LajmeTxt;?>"></textarea> <script type="text/javascript"> CKEDITOR.replace( 'LajmeTxt', { filebrowserBrowseUrl : 'includes/ckfinder/ckfinder.html', filebrowserImageBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Images', filebrowserFlashBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Flash', filebrowserUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files', filebrowserImageUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images', filebrowserFlashUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash' }); </script><br /> <label>Fotografia</label> <input type="file" size="20" value="<?=$LajmeImg;?>" id="LajmeImg" name="LajmeImg" /><br /> <label>Video</label><textarea id="LajmeVideo" name="LajmeVideo" value="<?=$LajmeVideo;?>" rows="4" wrap="soft" style="width:700px;" /></textarea><br /> <label>Tag</label><input id="LajmeTag" type="text" name="LajmeTag" value="<?=$LajmeTag;?>" /><br /> <label>Aktive</label><input id="LajmeAktiv" name="LajmeAktiv" type="checkbox" value="PO"><br /> <input type="submit" value="Vazhdo" name="add_lajme" /> </form> <? } echo '</div>'; include('poshte.php');?> edit page <?php include('header.php'); include ('includes/uploader.class.php'); $uploader = new uploader(); // Setting properties then Uploading the image $uploader->destDir = "D:/Program Files/VertrigoServ/www/oldi/imazhet/artikuj/"; $uploader->upload($_FILES['LajmeImg']); echo '<div class="majtas">'; if(!$_GET['lajmeid'] && !isset($_POST['do_edit']) && !isset($_POST['edit_lajme'])) { echo $error; // Shfaq listen e lajmeve lajmet_lista(); } // Has the edit form been submitted? if(isset($_POST['do_edit'])) { $LajmeID = $_POST['LajmeID']; $LajmeEmri = $_POST['LajmeEmri']; $KatLajmeID = $_POST['KatLajmeID']; // Kategoria Lajmeve $LajmeIntro = $_POST['LajmeIntro']; $LajmeTxt = $_POST['LajmeTxt']; $LajmeAktiv = $_POST['LajmeAktiv']; $LajmeTag = $_POST['LajmeTag']; $LajmeVideo = $_POST['LajmeVideo']; $LajmeLink = $_POST['LajmeLink']; //$LajmeImg = $_FILES['LajmeImg']['name']; // Me autoName = False; regjistron ne db emrin real te fotografise $LajmeImg = $uploader->source['name']; // Me autoName = true; regjistron ne db emrin random te fotografise i gjeneruar ne base64 $LajmeImg = $_POST['LajmeImg']; $fshij = $_POST['fshij']; // Ticked the 'delete category' box? If so, delete and echo message. if($fshij == 'fshij_LajmeID' && $error == '') { $sql = "DELETE FROM lajme WHERE LajmeID=$LajmeID LIMIT 1"; $query = mysql_query($sql) or die("Fatal error: ".mysql_error()); echo "<h3>U Fshi</h3>"; echo "<div class='success_message'>Lajme <b>$LajmeID</b> u fshi nga sistemi.</div>"; echo "<h2>What to do now?</h2><br />"; echo "Go to the <a href='lajme_edit.php'>edit lajme</a> page.</li>"; } else { // Validate the submitted information if(trim($LajmeID) == '0') { $error = '<div class="error_message">LajmeID - Attention! You cannot edit the main Administrator, use database.</div>'; } else if(trim($LajmeEmri) == '') { $error = '<div class="error_message">LajmeEmri - Attention! You must enter a first name.</div>'; } else if(trim($LajmeLink) == '') { $error = '<div class="error_message">LajmeUrl - Attention! You must enter a last name.</div>'; } // Password been entered? If so, validate and update information. if(trim($KatLajmeID) == '') { $error = '<div class="error_message">Attention! Nuk ke zgjedhur kategorine.</div>'; } else if(trim($LajmeIntro) == '') { $error = '<div class="error_message">Attention! Nuk ke vene Intro.</div>'; } else if(trim($LajmeEmri) == '') { $error = '<div class="error_message">Attention! Nuk ke vene emrin.</div>'; } if($error == '') { $sql = "UPDATE lajme SET KatLajmeID = '$KatLajmeID', LajmeEmri = '$LajmeEmri', LajmeLink = '$LajmeLink', LajmeIntro = '$LajmeIntro', LajmeTxt = '$LajmeTxt', LajmeVideo = '$LajmeVideo', LajmeTag = '$LajmeTag', LajmeImg = '$LajmeImg', LajmeAktiv = '$LajmeAktiv' WHERE LajmeID = '$LajmeID'"; $query = mysql_query($sql) or die("Fatal error: ".mysql_error()); // $sql2 = "SELECT * FROM lajme_kategori WHERE LKatAktiv = PO"; //$sql2 = "SELECT B.LKatEmri, A.LajmeID AS LajmeID, A.LajmeEmri AS LajmeEmri, A.LajmeLink AS LajmeLink, A.LajmeIntro AS LajmeIntro, A.LajmeTxt AS LajmeTxt, A.LajmeTag AS LajmeTag, A.LajmeVideo AS LajmeVideo, A.LajmeAktiv AS LajmeAktiv, B.LKatAktiv = LKatAktiv FROM lajme A LEFT JOIN lajme_kategori B ON A.KatLajmeID = B.LKatID WHERE B.LKatID = KatLajmeID AND LKatAktiv = PO AND LajmeAktiv = PO "; //$sql2 = "SELECT * FROM lajme_Kategori WHERE LKatID = '$KatLajmeID'"; //$result2 = mysql_query($sql2); echo "<h2>U Modifikua</h2>"; echo "<div class='success_message'>Lajmi u modifikua: <b>$LajmeEmri ($LajmeLink)</b> me ID <b>$LajmeID </b>.</div>"; echo "<h2>What to do now?</h2><br />"; echo "Go to the <a href='lajme_edit.php'>edit lajme</a> page.</li>"; } } } // Has a category been selected to edit? if($_GET['lajmeid'] && !isset($_POST['do_edit']) && !isset($_POST['edit_lajme']) || $error != '') { $LajmeID = $_GET['lajmeid']; $sql = "SELECT B.LKatEmri, A.LajmeID AS LajmeID, A.LajmeEmri AS LajmeEmri, A.LajmeLink AS LajmeLink, A.LajmeIntro AS LajmeIntro, A.LajmeTxt AS LajmeTxt, A.LajmeTag AS LajmeTag, A.LajmeImg AS LajmeImg, A.LajmeVideo AS LajmeVideo, A.LajmeAktiv AS LajmeAktiv, A.KatLajmeID AS KatLajmeID FROM lajme A LEFT JOIN lajme_kategori B ON A.KatLajmeID = B.LKatID WHERE B.LKatID = KatLajmeID AND A.LajmeID='$LajmeID'"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $LajmeEmri = $row['LajmeEmri']; $LajmeLink = $row['LajmeLink']; $LajmeIntro = $row['LajmeIntro']; $LajmeTxt = $row['LajmeTxt']; $LajmeVideo = $row['LajmeVideo']; $LajmeTag = $row['LajmeTag']; $LajmeImg = $row['LajmeImg']; $LajmeAktiv = $row['LajmeAktiv']; $KatLajmeID = $row['KatLajmeID']; $LKatEmri = $row['LKatEmri']; echo $error; echo "<h2>Informacionet per lajmin ( ".stripslashes($row['LajmeEmri'])." )</h2>"; ?> <form action="" method="post"> <input type="hidden" name="LajmeID" value="<?=$row['LajmeID'];?>" /> <label style="width: 28%;">Kategoria</label> <select name="KatLajmeID"> <option selected value="<?=stripslashes($row['KatLajmeID']);?>"><?=$LKatEmri ?></option> <?php // Marrja e te dhenave ekzistente ?> <?php $sql2 = "SELECT * FROM lajme_kategori WHERE LKatAktiv = 'PO'"; // Query per te marre kategorite nga database $result2 = mysql_query($sql2); ?> <? while($kategoria = mysql_fetch_array($result2)) { echo '<option value="'.stripslashes($kategoria['LKatID']).'">'.stripslashes($kategoria['LKatEmri']).'</option>'; // Lista e kategorive } ?> </select> <label>Titulli</label> <input type="text" name="LajmeEmri" value="<?=stripslashes($row['LajmeEmri']);?>" /><br /> <label>Linku</label> <input type="text" name="LajmeLink" value="<?=stripslashes($row['LajmeLink']);?>" /><br /> <label>Intro</label><textarea id="LajmeIntro" name="LajmeIntro" /><?=stripslashes($row['LajmeIntro']);?></textarea> <script type="text/javascript"> CKEDITOR.replace( 'LajmeIntro', { filebrowserBrowseUrl : 'includes/ckfinder/ckfinder.html', filebrowserImageBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Images', filebrowserFlashBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Flash', filebrowserUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files', filebrowserImageUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images', filebrowserFlashUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash', }); </script><br /> <label>Lajmi</label> <textarea id="LajmeTxt" name="LajmeTxt" /><?=stripslashes($row['LajmeTxt']);?></textarea> <script type="text/javascript"> CKEDITOR.replace( 'LajmeTxt', { filebrowserBrowseUrl : 'includes/ckfinder/ckfinder.html', filebrowserImageBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Images', filebrowserFlashBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Flash', filebrowserUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files', filebrowserImageUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images', filebrowserFlashUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash' }); </script><br /> <label>Video</label> <textarea id="LajmeVideo" name="LajmeVideo" rows="6" wrap="soft" style="width:700px;" /><?=stripslashes($row['LajmeVideo']);?></textarea><br /> Fotografia: <img src="../imazhet/artikuj/<?=stripslashes($row['LajmeImg']);?>" width="150" align="middle" /><br /> <label>Fotografia</label> <input type="file" size="20" name="LajmeImg" value="<?=stripslashes($row['LajmeImg']);?>" /><br /> <label>Tag</label> <input type="text" name="LajmeTag" value="<?=stripslashes($row['LajmeTag']);?>" /><br /> <label style="width: 50%;">Aktive</label> <input id="LajmeAktiv" name="LajmeAktiv" type="checkbox" <?php if ($LajmeAktiv == "PO") { echo "checked";} ?> value="PO"> <br /><br /> <div class="error_message">Do fshish kete lajm? (Nuk kthehet mbrapsh!) <input type="checkbox" class="checkbox" name="fshij" value="fshij_LajmeID"></div> <input type="submit" value="Ruaje" name="do_edit" /> </form> <? } echo '</div>'; include('poshte.php'); ?> uploaded class <?php /** * Uploader is a file transfer class. it can upload files and images. * It also can resize and crop images. * Works on PHP 5 * @author Alaa Al-Hussein * @link http://www.freelancer-id.com/projects * @version 1.0 * */ class uploader{ /** * Array, The file object as $_FILES['element']. * String, file location. */ public $source; /** * Destination file location as folder. */ public $destDir; /** * Directory for Resized images. */ public $resizeDir; /** * Directory for Cropped images. */ public $cropDir; /** * stores information for uploading file */ private $info = ''; /** * Enabling autoName will generate an auto file name for the uploaded file. */ public $autoName = true; /** * Handles the error when it occurs. */ private $errorMsg = ''; /** * new width for resizing and cropping. */ public $newWidth; /** * new height for resizing and cropping. */ public $newHeight; /** * TOP postion to cropping image. */ public $top = 0; /** * LEFT position for cropping image. */ public $left = 0; /** * JPG quality (0 - 100). used for image resizing or cropping. */ public $quality = 60; public function __construct(){ //nothing } /** * Uploads the file to the server. * @param Array $_FILES[] */ public function upload($source){ if($source != ""){ $this->source = $source; } if(is_array($this->source)){ if($this->fileExists()){ return false; } return $this->copyFile(); } else { return $this->source; } } /** * return the error messages. * @return String messages. */ public function getError(){ return $this->errorMsg; } /** * Get uploading information. */ public function getInfo(){ return $this->info; } /** * Get file ex. */ function getEx(){ return strtolower(substr($this->source['name'], strrpos($this->source['name'], '.') + 1)); } /** * Get random name. */ function randName(){ return substr(base64_encode(uniqid()),0,10); } /** * Copy the uploaded file to destination. */ private function copyFile(){ if(!$this->isWritable()){ $this->errorMsg .= '<div>Error, the directory: ('.$this->destDir.') is not writable. Please fix the permission to be able to upload.</div>'; return false; } $this->source['name'] = ($this->autoName) ? $this->randName().'.'.$this->getEx(): $this->source['name']; if(copy($this->source['tmp_name'],$this->destDir . $this->source['name'])){ // Done. $this->info .= '<div>file was uploaded successfully.</div>'; } else { $this->errorMsg .= '<div>Error, the file was not uploaded correctly because of an internal error. Please try again, if you see this message again, please contact web admin.</div>'; } } /** * Checks if the file was uploaded. * @return boolean */ private function uploaded(){ if($this->source['tmp_name']=="" || $this->source['error'] !=0){ $this->errorMsg .= '<div>Error, file was not uploaded to the server. Please try again.</div>'; return false; } else return true; } /** * Prepares the directory. */ private function preDir(){ if($this->destDir!="" && substr($this->destDir, -1,1) != "/"){ $this->destDir = $this->destDir . '/'; } if($this->resizeDir!="" && substr($this->resizeDir, -1,1) != "/"){ $this->destDir = $this->resizeDir . '/'; } if($this->cropDir!="" && substr($this->cropDir, -1,1) != "/"){ $this->destDir = $this->cropDir . '/'; } } /** * Check if the folder is writable or not. * @return boolean */ private function isWritable(){ $err = false; if(!is_writeable($this->destDir) && $this->destDir!=""){ $this->errorMsg .= '<div>Error, the directory ('.$this->destDir.') is not writeable. File could not be uploaded.</div>'; $err = true; } if(!is_writeable($this->resizeDir) && $this->resizeDir!=""){ $this->errorMsg .= '<div>Error, the directory ('.$this->resizeDir.') is not writeable. File could not be resized.</div>'; $err = true; } if(!is_writeable($this->cropDir) && $this->cropDir!=""){ $this->errorMsg .= '<div>Error, the directory ('.$this->cropDir.') is not writeable. File could not be cropped.</div>'; $err = true; } if($err == true){ return false; } else { return true; } } /** * Checks if the file exists on the server * @return boolean */ private function fileExists(){ $this->preDir(); if(file_exists($this->destDir.$this->source)){ $this->errorMsg .= '<div>Upload error because file already exists.</div>'; return true; } else { return false; } } /** /586742130./8532 Crops image. * @return String fileName or False on error */ public function crop($file='',$width='',$height='',$top='',$left=''){ if($file!=""){ $this->source = $file;} if ($width != '') $this->newWidth = $width; if ($height != '') $this->newHeight = $height; if ($top != '') $this->top = $top; if ($left != '') $this->left = $left; return $this->_resize_crop(true); } /** * Resizes an image. * @return String fileName or False on error */ public function resize($file='',$width='',$height=''){ if($file!=""){ $this->source = $file; } if($width != '') $this->newWidth = $width; if($height != '') $this->newHeight = $height; return $this->_resize_crop(false); } /** * Get the Temp file location for the file. * If the Source was a file location, it returns the same file location. * @return String Temp File Location */ private function getTemp(){ if(is_array($this->source)){ return $this->source['tmp_name']; } else { return $this->source; } } /** * Get the File location. * If the source was a file location, it returns the same file location. * @return String File Location */ private function getFile(){ if(is_array($this->source)){ return $this->source['name']; } else { return $this->source; } } /** * Resize or crop- the image. * @param boolean $crop * @return String fileName False on error */ private function _resize_crop ($crop) { $ext = explode(".",$this->getFile()); $ext = strtolower(end($ext)); list($width, $height) = getimagesize($this->getTemp()); if(!$crop){ $ratio = $width/$height; if ($this->newWidth/$this->newHeight > $ratio) { $this->newWidth = $this->newHeight*$ratio; } else { $this->newHeight = $this->newWidth/$ratio; } } $normal = imagecreatetruecolor($this->newWidth, $this->newHeight); if($ext == "jpg") { $src = imagecreatefromjpeg($this->getTemp()); } else if($ext == "gif") { $src = imagecreatefromgif ($this->getTemp()); } else if($ext == "png") { $src = imagecreatefrompng ($this->getTemp()); } if($crop){ $pre = 'part_'; if(imagecopy($normal, $src, 0, 0, $this->top, $this->left, $this->newWidth, $this->newHeight)){ $this->info .= '<div>image was cropped and saved.</div>'; } $dir = $this->cropDir; } else { $pre = 'thumb_'; if(imagecopyresampled($normal, $src, 0, 0, 0, 0, $this->newWidth, $this->newHeight, $width, $height)){ $this->info .= '<div>image was resized and saved.</div>'; } $dir = $this->resizeDir; } if($ext == "jpg" || $ext == "jpeg") { imagejpeg($normal, $dir . $pre . $this->getFile(), $this->quality); } else if($ext == "gif") { imagegif ($normal, $dir . $pre . $this->getFile()); } else if($ext == "png") { imagepng ($normal, $dir . $pre . $this->getFile(),0); } imagedestroy($src); return $src; } } ?> Can someone help me, please? Thank you in advance! I just started with php and made an image. But when I try to open it in my browser, it shows a broken image icon. I have put the font in the same folder as the .php file, but it doesn't work. Can somebody help me solve this problem? Here is the code: Code: [Select] <?php $font_path = "nakedchick.TTF"; $font_size = 30; $img_number = imagecreate(300,50); $backcolor = imagecolorallocate($img_number,0,162,255); $textcolor = imagecolorallocate($img_number,255,255,255); imagefill($img_number,0,0,$backcolor); $number = " So your ip is $_SERVER[REMOTE_ADDR]? "; ImageTTFText($img_number, $font_size,10,5,5,$number,$font_path,$textcolor); header("Content-type: image/png"); imagepng($img_number); ?> And also the files: (.php in attachment) http://falcogerritsjans.nl/u/signature2.php http://falcogerritsjans.nl/u/nakedchick.ttf I came up with the following script for displaying an uploaded picture on a webpage but for some reason I can't pinpoint, the picture won't be displayed. I checked my database from php myadmin and sure enough, the picture was successfully uploaded but somehow, the picture won't be displayed. So here is the display script. I named it display_pic.php Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user //Start session session_start(); //Connect to database require ('config.php'); //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //include the config file require('config.php'); $image = stripslashes($_REQUEST[imname]); $rs = mysql_query("SELECT* FROM images WHERE member_id = '".$_SESSION['id']."' AND image_cartegory = 'main' "); $row = mysql_fetch_assoc($rs); $imagebytes = $row[image]; header("Content-type: image/jpeg"); print $imagebytes; ?> The tag on the html page that's supposed to display the picture reads something like this <img src="display_pic.php" width="140" height="140"> And just in case this might help, I will include the image upload script below, which I think worked just fine because my values were successfully inserted into the database. Code: [Select] <?php //This file inserts the main image into the images table. //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user //Start session session_start(); //Connect to database require ('config.php'); //Check whether the session variable id is present or not. If not, deny access. if(!isset($_SESSION['id']) || (trim($_SESSION['id']) == '')) { header("location: access_denied.php"); exit(); } else{ // Make sure the user actually // selected and uploaded a file if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { // Temporary file name stored on the server $tmpName = $_FILES['image']['tmp_name']; // Read the file $fp = fopen($tmpName, 'r'); $data = fread($fp, filesize($tmpName)); $data = addslashes($data); fclose($fp); // Create the query and insert // into our database. $query = "INSERT INTO images (member_id, image_cartegory, image_date, image) VALUES ('{$_SESSION['id']}', 'main', NOW(), '$data')"; $results = mysql_query($query); // Print results print "Thank you, your file has been uploaded."; } else { print "No image selected/uploaded"; } // Close our MySQL Link mysql_close(); } //End of if statmemnt. ?> So any insights as to why the script fails to display the image? Any help is appreciated. Hi, sorry for a noob question, but I'm having problem with this small code that doesn't work. I have secret image path written in php file which must be given to HTML parameter. After this I want to make PHP send file of mime type "audio/mpeg3". The thing is to hide actual file paths. Every code is as simple as it can get hopefully. I run these files locally with Firefox and they are located in the same folder: phptest.html, phptest.php, car.jpg. I have HTML file: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <p>Image given by .php file:</p> <img src="phptest.php?id=1"> </body> </html> It's really simple, just look at body tag. The whole phptest.php file: <?php $path=''; if ($_GET["id"] === "1"){ //More "if" statements planned $path = 'car.jpg'; } header('Content-Type: image/jpeg'); //Don't need too much headers? readfile($path); exit(); ?> PHP is supposed to read file with "id" paramenter. But Somehow this doesn't work. after spending many hours thinking this through and not really getting anywhere, trying to figure out how this site works, so that i can replicate it and make a single image from multiple images that are positioned overlaying with css positioning
the site in question is: http://www.dahippo.c...6360ZZ0ZZ0ZZ0ZZ
it is a type of calculator for an online game, the part that interests me is the image of the ship that is built up from many images
is also uses a php script to place all these images into on image file outputted to html, this is what interests me and i am trying to recreate, like he http://www.dahippo.c...6360ZZ0ZZ0ZZ0ZZ
here is the outputted html:
<html> <head> <meta name="viewport" content="width=device-width, minimum-scale=0.1"> <title>get.php (635x317)</title> </head> <body style="margin: 0px;"> <img style="-webkit-user-select: none; cursor: -webkit-zoom-in;" src="http://www.dahippo.com/bp/ship/get.php?image=4J01Q180O0K0E013C3A3C3A3636360ZZ0ZZ0ZZ0ZZ" width="408" height="204"> </body> </html>what php code used in the get.php script make all these images with css positioning into 1 image? i have asked the site owner, and got no reply :/ Hi.., I use below method to export data to excel. header('Content-type: application/ms-excel'); header('Content-Disposition: attachment; filename=abc.xls'); if I run the script from the server. (http://localhost/export.php) it is work. (pop-up window if i want save or open the file) but if i run the script from the client (http://192.168.1.5/export.php) it is not work. (nothing happen) any idea how to solve this? |