PHP - User Avatar Not Uploading Even Tho Its Correct Image Type (.jpg/.png)
Hey guys I have this script that edits a users profile, but the problem is that it doesnt want to upload it to the server and keeps saying.
Files must be either JPEG, GIF, or PNG and less than 10,000 kb <?php if(empty($_GET['id']) ) { echo 'Category not specified'; } else { mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("chat"); $result = mysql_query("SELECT * FROM users WHERE user_id = '$_GET[id]'"); $query = mysql_fetch_array($result); if (isset($_POST['submit'])) { $target = "mainnewsimg/"; $target = $target . basename( $_FILES['photo']['name']); // Set global variables to easier names $pic=($_FILES['photo']['name']); if (($_FILES["photo"]["type"] == "image/gif") || ($_FILES["photo"]["type"] == "image/jpeg") || ($_FILES["photo"]["type"] == "image/png" ) && ($_FILES["photo"]["size"] < 10000)) { if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { mysql_query("UPDATE users SET level ='". $_POST['rank'] ."', email='". $_POST['email'] ."', fname='". $_POST['fname'] ."', lname='". $_POST['lname'] ."', avatar='$pic' WHERE user_id='". $_GET['id'] ."' "); echo "user updated"; } else { echo "file hasent been moved to uploads"; } } else { echo "Files must be either JPEG, GIF, or PNG and less than 10,000 kb"; } //mysql_query("UPDATE Persons SET level = '36'WHERE user_id = '$_GET[id]'"); } ?> <?php echo $query['username']; ?> <form method="post" action=""> <table> <tbody> <tr><td class="first"></td> <td><?php echo $query['user_id']; ?></td></tr> <tr><td class="first">First Name</td> <td><input type="text" name="fname" value="<?php echo $query['fname']; ?>" ></td></tr> <tr><td class="first">Last Name</td> <td><input type="text" name="lname" value="<?php echo $query['lname']; ?>" ></td></tr> <tr><td class="first">Email</td> <td><input type="text" name="email" value="<?php echo $query['email']; ?>" ></td></tr> <tr><td class="first">Rank</td> <td><select name="rank"> <option value="0" <?php if($query['level']=="0") { echo "selected"; }?>>Unactivated</option> <option value="1" <?php if($query['level']=="1") { echo "selected"; }?>>Banned</option> <option value="2" <?php if($query['level']=="2") { echo "selected"; }?>>Regular User</option> <option value="3" <?php if($query['level']=="3") { echo "selected"; }?>>Donator</option> <option value="4" <?php if($query['level']=="4") { echo "selected"; }?>>Moderator</option> <option value="5" <?php if($query['level']=="5") { echo "selected"; }?>>Administrator</option> <option value="6" <?php if($query['level']=="6") { echo "selected"; }?>>Owner</option> </select> </td></tr> <tr><td class="first">User Avatar</td> <td><input type="file" name="photo"></td></tr> <tr><td class="first">Joined on</td> <td><input type="text" name="join" value="<?php echo date('d-F-Y',($query['join_date'])); ?>" disabled="disabled"></td></tr> <tr><td class="first">Last Access</td> <td><input type="text" name="access" value="" disabled="disabled"></td></tr> <tr><td></td> <td> <input type="submit" name="submit" value="Edit User"> </td></tr> </tbody></table> </form> <?php } ?> Similar Tutorialshi, i have made a website where people resgister their details of them and products. they have to enter the following details in form Name of company name of the product company address email id password mobile number contact and brief details about their company
user can then login with email id and pwd. now after login ..user will get a page where he can upload the photos of products images and their price, so now my question is that when he finishes uploading (|by clicking on upload button) the product images and price text box ..then on final uploaded webspage it should show all other things which he registerd before (company name , mobile number etc) along with images and price...hence the main question that user does not need to enter mobile and address while uploading images and filling proce ..but on the final page it should show mobile and address along with price and images..as user is not going to enter mobile and address again and again as he will have multiple products to upload.
Hi ppl got code problem cant get it show users avatar & blank avatar at same time not that good at php ppl. avatar box page Code: [Select] <style type="text/css"> #name_area{height:20px; padding:3px;}; </style> <script language="javascript"> <!-- function member_change(id){ <?php $allgames = mysql_query("SELECT * FROM games") or die (mysql_error()); $allgames_total = @mysql_num_rows($allgames); if($allgames_total!=0) { $i=0; while($i<$allgames_total) { ?> document.getElementById('<?php echo mysql_result($allgames, $i, 'game_id'); ?>').style.display = "none"; <?php $i++; } } ?> document.getElementById(id).style.display = "block"; } function show_name(name){ document.getElementById('name_area').innerHTML = name; } function hide_name(){ document.getElementById('name_area').innerHTML = ''; } //--> </script> <div style="text-align:left;"> Choose Squad: <select name="D1" onchange="member_change(this.options[this.selectedIndex].value)" class="standardforms"> <?php $allgames = mysql_query("SELECT * FROM games") or die (mysql_error()); $allgames_total = @mysql_num_rows($allgames); if($allgames_total!=0) { $i=0; while($i<$allgames_total) { $game = mysql_result($allgames, $i, 'game_title'); $members_total2 = mysql_num_rows(mysql_query("SELECT * FROM members WHERE game = '$game'")); if($members_total2!=0) { ?> <option value="<?php echo mysql_result($allgames, $i, 'game_id'); ?>"><?php echo mysql_result($allgames, $i, 'game_title'); ?></option> <?php } $i++; } } ?> </select><br /><br /> </div> <?php $allgames = mysql_query("SELECT * FROM games") or die (mysql_error()); $allgames_total = @mysql_num_rows($allgames); if($allgames_total!=0) { $i=0; while($i<$allgames_total) { $game = mysql_result($allgames, $i, 'game_title'); $members = mysql_query("SELECT * FROM members WHERE game = '$game'"); $members_total = @mysql_num_rows($members); if($allgames_total!=0) { ?> <div id="<?php echo mysql_result($allgames, $i, 'game_id'); ?>" style="display: block; text-align:left;"> <?php if($members_total!=0) { $d=0; while($d<$members_total) { ?> <a href="index.php?page=members&id=<?php echo mysql_result($members, $d, 'id'); ?>"><img onmouseover="show_name('<?php echo mysql_result($members, $d, 'username'); ?>')" onmouseout="hide_name()" src="user/<?php echo mysql_result($members, $d, 'avatar_link'); $filename = 'avatar_link'; if (file_exists($filename)) { echo "avatar_link"; } else { echo "avatars/blank.jpg"; } ?>" width="50" height="50" alt="<?php echo mysql_result($members, $d, 'username'); ?>" title="<?php echo mysql_result($members, $d, 'username'); ?>"/></a> <?php $d++; } } } echo "</div>"; $i++; } } ?> <div id="name_area"></div> I'm trying out a script that lets users upload files into a directory, the file path then should be saved on the user information in the database. This script keeps throwing "Undefined index: file" errors, even though I;m sure it should be defined. Could someone take a look please? Here's the form I'm using: Code: [Select] <form id ='change0' action ='pic_up.php' method ='post' accept-charset='UTF-8'> <fieldset > <legend>Confirm Details</legend> <input type ='hidden' name ='file' id ='file' value ='800000'/> <label for ='file' >Upload Profile Pictu </label> <input type ='file' name ='file' id ='file' /> <input type ='submit' name ='Submit' value ='Submit' /> </fieldset> </form> Here's the PHP script: Code: [Select] <?php include 'connect.php'; session_start(); $_SESSION['username']; $username = $_SESSION['username']; if(!(isset($_SESSION['login']) && $_SESSION['login']!= " ")){ header("Location: login.php"); } $tablename = 'usr_test'; $targ = "localhost/img/"; $targ = $targ . basename($_FILES['file']['name']); $file = ($_FILES['file']['name']); mysql_query("INSERT INTO $tablename (pic) VALUES ($file) WHERE usr = '$username'"); if(move_uploaded_file($_FILES['file']['tmp_name'], $targ)) { echo "File ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, not happening"; } ?> Hi, I got this code which is meant to display the login details of the person that is logged in, however it just displays the details of the last person in the mysql table. I have set up some test logins, so if I login as paul1 the details for paul3 are displayed...confused Anyway, here is the page which displays the details Code: [Select] <?php session_start(); // This checks to make sure the session variable is registered // WARNING: DO NOT DELETE THE FOLLOWING LINE OF TEXT if( isset($_SESSION['username']) && isset($_SESSION['sid'])) { // You are free to edit the following code to suit your requirements include_once("../../data/server.php"); include_once("../../lib/userdata.php"); // THIS BIT WORKS AND DISPLAYS THE USERNAME $data = mysql_query("SELECT * FROM members") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { include("../../lib/userinfo.php"); //////////////////////////////////////////// WARNING: YOU SHOULD NOT EDIT ANYTHING ABOVE THIS LINE //////////////////////////////////////////////////////// ECHO <<<PAGE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>$siteName</title> <link rel="stylesheet" href="../../userstylesheet.css" type="text/css" /> </head> <div id="page"> <img alt="" src="../../images/leftCurve" height="6" width="6" id="left" /> <img alt="" src="../../images/rightCurve.gif" height="6" width="6" id="right" /> <div id="pageName"> <h1>$siteName</h1> </div> <div id="pageNav"> <div id="sectionLinks"> <a href="profile.php?username=$username">My Profile</a> <a href="modify.php?username=$username">Personal Details</a> <a href="message.php?username=$username">Messages</a> <a href="../../logout.php?username=$username">Logout</a></div> </div> <div id="content"> <div class="feature"> <h2>Welcome $username </h2> <p>This is the demonstration home.html template. You are free to edit this or any of the other templates to suit your own needs. </p> <p>This is the first page your member will see once they have logged in. </p> <p>If you look at the code for this page, you will see that all HTML code is placed between the ***PAGE and PAGE; tags. Please note that the three * should be replaced with the < character. This format must be kept to ensure that the user variables work. Changing this format may result in errors being returned.</p> <p>You may call member information using the $ tag and the variable name eg $ firstname without the space, will show the members first name, such as $firstname</p> <p>For any information please visit our site http://www.membersitemaker.co.uk. User guides will be added shortly and the forum will soon be full of help. </p> </div> </div> <div id="information"> <a href="#">About Us</a> | <a href="#">Site Map</a> | <a href="#">Privacy Policy</a> | <a href="#">Contact Us</a> | ©2011 $siteName </div> </div> </body> </html> PAGE; } //////////////////////////////////////// WARNING: DO NOT DELETE ANYTHING BELOW THIS LINE ////////////////////////////////////////////////////////// } else { // This will redirect the user to the login page if the session variables do not exist header( "Location: ../../../login.html" ); } ?> And here is the code for userdata.php Code: [Select] <?php // Decode sitename function decode_variable(&$siteName) { $siteName = urldecode($siteName); $siteName = str_replace('%20',' ',$siteName); return $siteName; } decode_variable($siteName); // Connnect to MySQL database include_once("../../data/mysql.php"); $mysqlPassword = (base64_decode($mysqlpword)); $db = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die ("Error connecting to database"); mysql_select_db("$dbname", $db) or die ("An error occured when connecting to database"); // Carry out MySQL query ?> and userinfo.php Code: [Select] <?php $username = $info['username']; $firstname = $info['firstname']; $lastname = $info['lastname']; $address = $info['address']; $town = $info['town']; $county = $info['county']; $postcode = $info['postcode']; $email = $info['email']; $birth_year = $info['birth_year']; $country = $info['country']; $telephone_number = $info['telephone_number']; $mobile_number = $info['mobile_number']; $nickname = $info['nickname']; As always, your help is much appreciated Paul This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=327636.0 I am trying to upload files to a user profile system. here is the profile page Code: [Select] <?php include('core/init.inc.php'); if (isset($_POST['email'], $_POST['location'], $_POST['about'])) { $errors = array(); if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) { $errors[] = "The email address you entered is not valid"; } if(preg_match('#^[a-z0-9 ]+$#i',$_POST['location'])===0) { $errors[] = 'Your location must only contain A-Z 0-9 and spaces.'; } if (empty($_FILES['avatar']['tmp_name']) === false) { $file_ext = end(explode('.', $_FILES['avatar']['name'])); if(in_array(strtolower($file_ext), array('jpg', 'jpeg', 'gif', 'png')) === false) { $errors[] = 'Your avatar must be an image.'; } } if(empty($errors)) { print_r($_FILES); set_profile_info($_POST['email'],$_POST['location'],$_POST['about'], (empty($_FILES['avatar']['tmp_name'])) ? false : $_FILES['avatar']['tmp_name']); } $userinfo = array( 'email' => htmlentities($_POST['email']), 'location' => htmlentities($_POST['location']), 'about' => htmlentities($_POST['about']) ); } else { $userinfo = fetch_user_info($_SESSION['uid']); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Edit your Profile</title> </head> <body> <div> <?php if(isset($errors) == false) { echo 'Click update to edit your profile.'; } else if(empty($errors)) { echo 'Your profile has been updated.'; } else { echo '<ul><li>', implode('</li><li>', $errors), '</li></ul>'; } ?> </div> <form action="" method="post" enctype="multipart/form-data"> <div> <label for="email">Email: </label> <input type="text" name="email" id="email" value="<?php echo $userinfo['email']; ?>" /> </div> <div> <label for="location">Location: </label> <input type="text" name="location" id="location" value="<?php echo $userinfo['location']; ?>" /> </div> <div> <label for="about">About Me: </label> <textarea name="about" id="about" rows="14" cols="50"><?php echo strip_tags($userinfo['about']); ?></textarea> </div> <div> <label for="avatar">Avatar: </label> <input type="file" name="avatar" id="avatar"/> </div> <div> <input type="submit" value="Update" /> </div> </form> </body> </html> here is the function taken from an external file Code: [Select] function set_profile_info($email, $location,$about,$avatar) { $email = mysql_escape_string(htmlentities($email)); $about = mysql_escape_string(nl2br(htmlentities($about))); $location = mysql_escape_string($location); if (file_exists($avatar)) { $src_size = getimagesize($avatar); if ($src_size['mime'] === 'image/jpeg') { $src_img = imagecreatefromjpeg($avatar); } else if ($src_size['mime'] === 'image/png') { $src_img = imagecreatefrompng($avatar); } else if ($src_size['mime'] === 'image/gif') { $src_img = imagecreatefromgif($avatar); } else { $src_img = false; } if ($src_img !== false) { $thumb_width= 200; if($src_size[0] <= $thumb_width) { $thumb = $src_img; } else { $new_size[0] = $thumb_width; $new_size[1] = ($src_size[1] / $src_size[0]) * $thumb_width; $thumb = imagecreatetruecolor($new_size[0], $new_size[1]); imagecopyresampled($thumb, $src_img, 0, 0, 0, 0, $new_size[0], $new_size[1], $src_size[0], $src_size[1]); } imagejpeg($thumb, "{$GLOBALS['path']}/user_avatars/{$_SESSION['uid']}.jpg"); } } $sql = "UPDATE `users` SET `user_email` = '{$email}', `user_about` = '{$about}', `user_location` = '{$location}' WHERE `user_id` = {$_SESSION['uid']}"; mysql_query($sql); } Below I have returned the array of files to check if its been uploaded correctly. Array ( [avatar] => Array ( [name] => Sonic.jpg [type] => image/jpeg [tmp_name] => /var/tmp/php.waq8n [error] => 0 [size] => 48477 ) ) But I get this error message. Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '/var/tmp/php.waq8n' is not a valid JPEG file in /web/stud/u0963643/userprofilesection/finaluserprofile/core/inc/user.inc.php on line 71 If someone could point out where in this code I have made an error I would be very grateful Thanks Jamie 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. This site was moved over from one server to another server. The image upload function was working fine on the old server, but when the files etc. were moved over to the new server, this is the resulting error when trying to upload an image: HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request. This is what I generated in Chrome (using developer tools): Code: [Select] Request URL:http://thedogrescuersinc.ca/imagedog_panel.php?imageid=158 Request Method:POST Status Code:500 Internal Server Error Request Headersview source Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3 Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 Cache-Control:max-age=0 Connection:keep-alive Content-Length:24564 Content-Type:multipart/form-data; boundary=----WebKitFormBoundary4zUh1NSdGFj27Fsy Cookie:user=4667623; PHPSESSID=dkb6a8tg4ck00dj9bg568vknj2 Host:thedogrescuersinc.ca Origin:http://thedogrescuersinc.ca Referer:http://thedogrescuersinc.ca/imagedog_panel.php?imageid=158 User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11 Query String Parametersview URL encoded imageid:158 Request Payload ------WebKitFormBoundary4zUh1NSdGFj27Fsy Content-Disposition: form-data; name="change_pic" 1 ------WebKitFormBoundary4zUh1NSdGFj27Fsy Content-Disposition: form-data; name="userfile"; filename="adopt_a_dog_oakville_ontario.jpg" Content-Type: image/jpeg ------WebKitFormBoundary4zUh1NSdGFj27Fsy Content-Disposition: form-data; name="change_pic" CLICK HERE TO UPLOAD IMAGE ------WebKitFormBoundary4zUh1NSdGFj27Fsy-- Response Headersview source Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Connection:close Content-Type:text/html; charset=UTF-8 Date:Wed, 29 Feb 2012 16:49:48 GMT Expires:Thu, 19 Nov 1981 08:52:00 GMT Pragma:no-cache Server:Apache Transfer-Encoding:chunked Any ideas, suggestions would be appreciated. Hi all, I have the following script which uploads 1 image per testimonial, and stores the url in the database, in a field named 'Images'. I have added more upload fields to my form and named them images 2,images 3 etc, and then i tried to copy the following code to upload the urls in to the extra fields i mage for the urls in the database, ('Images2','Images3' etc etc), but i am getting a blank page now. I even copied teh function and adjusted the names...eg $imgname2, 3 etc. Can anybody help me please? Here is the code that deals with the image upload Thanks Code: [Select] <p align="center"> </p> </body> <?php $con = mysql_connect("localhost","xxxxxxxxxxxxxxxxx","xxxxxxxxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxxxxxxxxxx", $con); $image_tmpname = $_FILES['images']['name']; $imgdir = "uploaded_images/"; $imgname = $imgdir.$image_tmpname; if(move_uploaded_file($_FILES['images']['tmp_name'], $imgname)) { list($width,$height,$type,$attr)= getimagesize($imgname); switch($type) { case 1: $ext = ".gif"; break; case 2: $ext = ".jpg"; break; case 3: $ext = ".png"; break; default: echo "Not acceptable format of image"; } $sql="INSERT INTO testimonials (CustomerName, Town, Testimonial, SortOrder, Images) VALUES ('$_POST[customername]','$_POST[town]','$_POST[testimonial]','$_POST[sort_order]','$imgname')"; } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "<p align=center><b>1 testimonial added</b></p>"; mysql_close($con); ?> </html> Well i have a php script which i use to upload jpg or gif images only... I want that whenever user uploads an image of any resolution my script transforms it to 100*100 resolution.. What should i do... Here is my PHP Script... Code: [Select] $_FILES["file"]["name"]=$_SESSION['id'].".jpg"; if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { /* echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; */ if (file_exists("upload/" . $_FILES["file"]["name"])) { echo " You have already uploaded your profile pic..."; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); //rename("/upload/" . $_FILES["file"]["name"], "/upload/" . $_SESSION['id'] ); $_SESSION['result']="PROFILE SETUP SUCCESSFULL"; header('location:members.php'); } } } else { echo "Invalid file"; } } Hi there. I am trying to make a simple script. I am tryng to make my friend a website so he can add his cars to an online showroom. I.E: one page to add the cars info and upload an image. then one page to display all the info. I currently have nailed adding the info to the database and showing it in an array but i am having trouble adding an upload box on the form...adding the image info to the db and then showing the image in the info array. This is the code i have: addcar.html *This contains the form to add the vehicle* <HTML> <HEAD> <TITLE>Barry Ottley Motor Co - Quality Used Motors - Stanford-Le-Hope, Essex</TITLE> </HEAD> <BODY LINK="#000000" ALINK="#000000" VLINK="#000000"> <CENTER><IMG SRC="logo.jpg"></CENTER> <CENTER> <TABLE WIDTH="840" CELLPADDING="0" CELLSPACING="0" BORDER="0"> <TR> <TD WIDTH="186" valign="top"> <BR> <CENTER><A HREF="index.html"><IMG SRC="homepage.jpg" alt="Homepage" border="0"></A></CENTER> <CENTER><A HREF="showroom.php"><IMG SRC="showroom.jpg" alt="Our Online Showroom" border="0"></A></CENTER> <CENTER><A HREF="location.html"><IMG SRC="ourlocation.jpg" alt="Our location" border="0"></A></CENTER> <CENTER><A HREF="aboutus.html"><IMG SRC="aboutus.jpg" alt="About Us" border="0"></A></CENTER> <CENTER><A HREF="contactus.php"><IMG SRC="contactus.jpg" alt="Contact Us" border="0"></A></CENTER> </TD> <TD WIDTH="30" valign="top"> </TD> <TD valign="top"> <FONT SIZE="2" FACE="ARIAL"> <CENTER><IMG SRC="vehicleadd.jpg"><IMG SRC="vehicleedit.jpg"><IMG SRC="vehicledelete.jpg"></CENTER> <CENTER><B>Add a Vehicle</B></CENTER> <BR> <form action="inserts.php" method="post" enctype="multipart/form-data"> <CENTER>Vehicle Name:</CENTER> <CENTER><input type="text" name="CarName"></CENTER> <br> <CENTER>Vehicle Type:</CENTER> <CENTER><input type="text" name="CarTitle"></CENTER> <br> <CENTER>Vehicle Price:</CENTER> <CENTER><input type="text" name="CarPrice"></CENTER> <br> <CENTER>Vehicle Mileage:</CENTER> <CENTER><input type="text" name="CarMiles"></CENTER> <br> <CENTER>Vehicle Description:</CENTER> <CENTER><textarea name="CarDescription" rows="10" cols="30"></textarea></CENTER> <br> <center>Upload Image</center> <CENTER><input type="file" name="image_file" /></CENTER> <BR> <CENTER><input type="Submit"></CENTER> </form> </TD> </TR> </TABLE> <BR><BR><BR><BR> <CENTER><FONT FACE="VERDANA" SIZE="1"> This website was designed and is hosted by <A HREF="http://www.IRCDirect.co.uk">IRC Direct Website Design™</A> 2010 </CENTER> <BR> <CENTER><A HREF="admin.php">Employee Area</A> </BODY> </HTML> inserts.php *This page contains the coding* *Currently adds the data but not image* <HTML> <HEAD> <TITLE>Barry Ottley Motor Co - Quality Used Motors - Stanford-Le-Hope, Essex</TITLE> </HEAD> <BODY LINK="#000000" ALINK="#000000" VLINK="#000000"> <CENTER><IMG SRC="logo.jpg"></CENTER> <CENTER> <TABLE WIDTH="840" CELLPADDING="0" CELLSPACING="0" BORDER="0"> <TR> <TD WIDTH="186" valign="top"> <BR> <CENTER><A HREF="index.html"><IMG SRC="homepage.jpg" alt="Homepage" border="0"></A></CENTER> <CENTER><A HREF="showroom.php"><IMG SRC="showroom.jpg" alt="Our Online Showroom" border="0"></A></CENTER> <CENTER><A HREF="location.html"><IMG SRC="ourlocation.jpg" alt="Our location" border="0"></A></CENTER> <CENTER><A HREF="aboutus.html"><IMG SRC="aboutus.jpg" alt="About Us" border="0"></A></CENTER> <CENTER><A HREF="contactus.php"><IMG SRC="contactus.jpg" alt="Contact Us" border="0"></A></CENTER> </TD> <TD WIDTH="30" valign="top"> </TD> <TD valign="top"> <FONT SIZE="2" FACE="ARIAL"> <CENTER><B>Vehicle Added</B></CENTER> <BR> <?php mysql_connect("localhost", "wormste1_barry", "barry") or die(mysql_error()); mysql_select_db("wormste1_barry") or die(mysql_error()); $CarName = mysql_real_escape_string(trim($_POST['CarName'])); $CarTitle = mysql_real_escape_string(trim($_POST['CarTitle'])); $CarPrice = mysql_real_escape_string(trim($_POST['CarPrice'])); $CarMiles = mysql_real_escape_string(trim($_POST['CarMiles'])); $CarDescription = mysql_real_escape_string(trim($_POST['CarDescription'])); if(isset($_POST['submit'])){ //directory in which your file will be uploaded $target_path = "images/"; $target_path = $target_path . basename( $_FILES['image_file']['name']); if(move_uploaded_file($_FILES['image_file']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['image_file']['name']). " has been uploaded"; //this is file name which you can store in database $file_name = $_FILES['image_file']['name']; /* Code for storing file name into db */ }else echo "Something went wrong =)"; } mysql_query("INSERT INTO cars (CarName, CarTitle, CarPrice, CarMiles, CarDescription) VALUES('$CarName', '$CarTitle', '$CarPrice', '$CarMiles', '$CarDescription' ) ") or die(mysql_error()); echo "The vehicle data has been added!"; ?> </TD> </TR> </TABLE> <BR><BR><BR><BR> <CENTER><FONT FACE="VERDANA" SIZE="1"> This website was designed and is hosted by <A HREF="http://www.IRCDirect.co.uk">IRC Direct Website Design™</A> 2010 </CENTER> <BR> <CENTER><A HREF="admin.php">Employee Area</A> </BODY> </HTML> Just in case: showroom.php *The page to display the info (Array): <HTML> <HEAD> <TITLE>Barry Ottley Motor Co - Quality Used Motors - Stanford-Le-Hope, Essex</TITLE> </HEAD> <BODY LINK="#000000" ALINK="#000000" VLINK="#000000"> <CENTER><IMG SRC="logo.jpg"></CENTER> <CENTER> <TABLE WIDTH="840" CELLPADDING="0" CELLSPACING="0" BORDER="0"> <TR> <TD WIDTH="186" valign="top"> <BR> <CENTER><A HREF="index.html"><IMG SRC="homepage.jpg" alt="Homepage" border="0"></A></CENTER> <CENTER><A HREF="showroom.php"><IMG SRC="showroom.jpg" alt="Our Online Showroom" border="0"></A></CENTER> <CENTER><A HREF="location.html"><IMG SRC="ourlocation.jpg" alt="Our location" border="0"></A></CENTER> <CENTER><A HREF="aboutus.html"><IMG SRC="aboutus.jpg" alt="About Us" border="0"></A></CENTER> <CENTER><A HREF="contactus.php"><IMG SRC="contactus.jpg" alt="Contact Us" border="0"></A></CENTER> </TD> <TD WIDTH="30" valign="top"> </TD> <TD valign="top"> <FONT SIZE="2" FACE="ARIAL"> <CENTER><B>Current Showroom</B></CENTER> <BR> <!-- VIEWING BIT --> <?php include('dbconnect.php') ?> <?php // Make a MySQL Connection $query = "SELECT * FROM cars"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH=100% BORDER=0>"; echo "<TR />"; echo "<TD WIDTH=30% VALIGN=TOP />"; echo " <IMG SRC=immg.gif /> "; echo "<br />"; echo "</TD>"; echo "<TD WIDTH=10 VALIGN=TOP />"; echo " "; echo "</TD>"; echo "<TD />"; echo "<font size=3 face=arial /><B >"; echo $row['CarPrice']; echo "</B><font size=2 face=arial />"; echo "<br />"; echo $row['CarTitle']; echo "<br />"; echo "Vehicle Type: "; echo $row['CarName']; echo "<br />"; echo "Vehicle Mileage: "; echo $row['CarMiles']; echo "<br />"; echo "Description: "; echo "<br />"; echo "<br />"; echo $row['CarDescription']; echo "<br />"; echo "</TD>"; echo "</TR>"; echo "</TABLE>"; echo "<hr WIDTH=100% COLOR=BLACK />"; } ?> <!-- END OF VIEWING BIT --> </TD> </TR> </TABLE> <BR><BR><BR><BR> <CENTER><FONT FACE="VERDANA" SIZE="1"> This website was designed and is hosted by <A HREF="http://www.IRCDirect.co.uk">IRC Direct Website Design™</A> 2010 </CENTER> <BR> <CENTER><A HREF="admin.php">Employee Area</A> </BODY> </HTML> Really could use a helping hand . Ian When i registred and try to upload a picture it doesnt show the picture but only a little icon that the picture doesnt excist. this is my code: Code: [Select] if(!empty($_FILES['photo'])) { if ((($_FILES["photo"]["type"] == "image/gif") || ($_FILES["photo"]["type"] == "image/jpeg") || ($_FILES["photo"]["type"] == "image/pjpeg") || ($_FILES["photo"]["type"] == "image/png")) && ($_FILES["photo"]["size"] < 1048576)){ $fileName = $_FILES['photo']['name']; $tmpName = $_FILES['photo']['tmp_name']; $fileSize = $_FILES['photo']['size']; $fileType = $_FILES['photo']['type']; if(!get_magic_quotes_gpc()){ if(isset($fileName)) { $fileName = addslashes($fileName); } } $url = $_FILES['photo']['name']; $idir = "upload/"; // Path To Images Directory $tdir = "upload/thumbs/"; // Path To Thumbnails Directory $twidth = "125"; // Maximum Width For Thumbnail Images $theight = "125"; // Maximum Height For Thumbnail Images $simg = imagecreatefromjpeg($_FILES["photo"]["tmp_name"]); // Make A New Temporary Image To Create The Thumbanil From $currwidth = imagesx($simg); // Current Image Width $currheight = imagesy($simg); // Current Image Height if ($currheight > $currwidth) { // If Height Is Greater Than Width $zoom = $twidth / $currheight; // Length Ratio For Width $newheight = $theight; // Height Is Equal To Max Height $newwidth = $currwidth * $zoom; // Creates The New Width } else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) $zoom = $twidth / $currwidth; // Length Ratio For Height $newwidth = $twidth; // Width Is Equal To Max Width $newheight = $currheight * $zoom; // Creates The New Height } $dimg = imagecreate($newwidth, $newheight); // Make New Image For Thumbnail imagetruecolortopalette($simg, false, 256); // Create New Color Pallete $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { // Counting Colors In The Image $colors = ImageColorsForIndex($simg, $i); // Number Of Colors Used ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); // Copy Resized Image To The New Image (So We Can Save It) imagejpeg($dimg, "$tdir" . $url); // Saving The Image $tmpName = "$tdir" . $url; $fp = fopen($tmpName, 'r'); $imgcontent = fread($fp, filesize($tmpName)); $imgcontent = addslashes($imgcontent); fclose($fp); unlink($tmpName); imagedestroy($simg); // Destroying The Temporary Image imagedestroy($dimg); // Destroying The Other Temporary Image Hi, This is my first post of PHP Freaks and your help would be greatly appreciated. I am currently creating a pinball fansite and I am having a really big problem. I have a page where users can input a pinball machine into my mysql database. Below is the code for this. The question I am asking is how do I edit this script so that I can upload an image with it? I have gone through various tutorials for days and days and days but cant seem to make it work with the code I have below. PLEASE CAN YOU HELP?? I have the following code for creating the pinball machine... Code: [Select] <?php //create_topic.php include 'connect.php'; include 'header.php'; echo '<h2>Create a Pinball Machine</h2>'; if($_SESSION['signed_in'] == false) { //the user is not signed in echo 'Sorry, you have to be <a href="signin.php">signed in</a> to create a pinball machine.'; } else { //the user is signed in if($_SERVER['REQUEST_METHOD'] != 'POST') { //the form hasn't been posted yet, display it //retrieve the categories from the database for use in the dropdown $sql = "SELECT cat_id, cat_name, cat_description FROM categories_pinballmachines"; $result = mysql_query($sql); if(!$result) { //the query failed, uh-oh :-( echo 'Error while selecting from database. Please try again later.'; } else { if(mysql_num_rows($result) == 0) { //there are no categories, so a topic can't be posted if($_SESSION['user_level'] == 1) { echo 'You have not created categories yet.'; } else { echo 'Before you can post a topic, you must wait for an admin to create some categories.'; } } else { echo '<form method="post" action="",enctype="multipart/form-data"> Name: <input type="text" name="topic_subject"><br /> Type:'; echo '<select name="topic_cat">'; while($row = mysql_fetch_assoc($result)) { echo '<option value="' . $row['cat_id'] . '">' . $row['cat_name'] . '</option>'; } echo '</select><br />'; echo 'Manufacturer: <input type="text" name="post_manufacturer"><br /> Release Date: <input type="text" name="post_releasedate"><br /> Number of Players: <input type="text" name="post_numberofplayers"><br /> Production: <input type="text" name="post_production"><br /><br /><br /> Concept by: <input type="text" name="post_conceptby"><br /> Design by: <input type="text" name="post_designby"><br /> Art by: <input type="text" name="post_artby"><br /> Dots/Animation by: <input type="text" name="post_dotsanimationby"><br /> Mechanics by: <input type="text" name="post_mechanicsby"><br /> Music by: <input type="text" name="post_musicby"><br /> Sound by: <input type="text" name="post_soundby"><br /> Software by: <input type="text" name="post_softwareby"><br /> <input type="submit" value="Create Pinball Machine" /> </form>'; } } } else { //start the transaction $query = "BEGIN WORK;"; $result = mysql_query($query); if(!$result) { //Damn! the query failed, quit echo 'An error occured while creating your topic. Please try again later.'; } else { //the form has been posted, so save it //insert the topic into the topics table first, then we'll save the post into the posts table $sql = "INSERT INTO topics_pinballmachines(topic_subject, topic_date, topic_cat, topic_by) VALUES('" . mysql_real_escape_string($_POST['topic_subject']) . "', NOW(), " . mysql_real_escape_string($_POST['topic_cat']) . ", " . $_SESSION['user_id'] . " )"; $result = mysql_query($sql); if(!$result) { //something went wrong, display the error echo 'An error occured while inserting your data. Please try again later.<br /><br />' . mysql_error(); $sql = "ROLLBACK;"; $result = mysql_query($sql); } else { //the first query worked, now start the second, posts query //retrieve the id of the freshly created topic for usage in the posts query $topicid = mysql_insert_id(); $sql = "INSERT INTO posts_pinballmachines(post_manufacturer, post_releasedate, post_numberofplayers, post_production, post_conceptby, post_designby, post_artby, post_dotsanimationby, post_mechanicsby, post_musicby, post_soundby, post_softwareby, post_date, post_topic, post_by) VALUES ('" . mysql_real_escape_string($_POST['post_manufacturer']) . "', '" . mysql_real_escape_string($_POST['post_releasedate']) . "', '" . mysql_real_escape_string($_POST['post_numberofplayers']) . "', '" . mysql_real_escape_string($_POST['post_production']) . "', '" . mysql_real_escape_string($_POST['post_conceptby']) . "', '" . mysql_real_escape_string($_POST['post_designby']) . "', '" . mysql_real_escape_string($_POST['post_artby']) . "', '" . mysql_real_escape_string($_POST['post_dotsanimationby']) . "', '" . mysql_real_escape_string($_POST['post_mechanicsby']) . "', '" . mysql_real_escape_string($_POST['post_musicby']) . "', '" . mysql_real_escape_string($_POST['post_soundby']) . "', '" . mysql_real_escape_string($_POST['post_softwareby']) . "', NOW(), " . $topicid . ", " . $_SESSION['user_id'] . " )"; $result = mysql_query($sql); if(!$result) { //something went wrong, display the error echo 'An error occured while inserting your post. Please try again later.<br /><br />' . mysql_error(); $sql = "ROLLBACK;"; $result = mysql_query($sql); } else { $sql = "COMMIT;"; $result = mysql_query($sql); //after a lot of work, the query succeeded! echo 'You have succesfully created <a href="topic_pinballmachines.php?id='. $topicid . '">your new pinball machines</a>.'; } } } } } include 'footer.php'; ?> and the following code is where the information is displayed... <?php //create_cat.php include 'connect.php'; include 'header.php'; $sql = "SELECT topic_id, topic_subject FROM topics_pinballmachines WHERE topics_pinballmachines.topic_id = " . mysql_real_escape_string($_GET['id']); $result = mysql_query($sql); if(!$result) { echo 'The topic could not be displayed, please try again later.'; } else { if(mysql_num_rows($result) == 0) { echo 'This topic doesn′t exist.'; } else { while($row = mysql_fetch_assoc($result)) { //display post data echo '<h2>PINBALL MACHINES</h2>'; echo '<table> <tr> <th colspan="2">' . $row['topic_subject'] . '</th> </tr>'; //fetch the posts from the database $posts_sql = "SELECT posts_pinballmachines.post_topic, posts_pinballmachines.post_manufacturer, posts_pinballmachines.post_releasedate, posts_pinballmachines.post_numberofplayers, posts_pinballmachines.post_production, posts_pinballmachines.post_conceptby, posts_pinballmachines.post_designby, posts_pinballmachines.post_artby, posts_pinballmachines.post_dotsanimationby, posts_pinballmachines.post_mechanicsby, posts_pinballmachines.post_musicby, posts_pinballmachines.post_soundby, posts_pinballmachines.post_softwareby, posts_pinballmachines.post_date, posts_pinballmachines.post_by, users.user_id, users.user_name FROM posts_pinballmachines LEFT JOIN users ON posts_pinballmachines.post_by = users.user_id WHERE posts_pinballmachines.post_topic = " . mysql_real_escape_string($_GET['id']); $posts_result = mysql_query($posts_sql); if(!$posts_result) { echo '<tr><td>The posts could not be displayed, please try again later.</tr></td></table>'; } else { while($posts_row = mysql_fetch_assoc($posts_result)) { echo ' <tr class="topic-post"> <td class="post-content2"><b>Manufacturer: </b> <td class="post-content">' . htmlentities(stripslashes($posts_row['post_manufacturer'])) . '</br></tr> <td class="post-content2"><b>Release Date: </b> <td class="post-content">' . htmlentities(stripslashes($posts_row['post_releasedate'])) . '</br></tr> <td class="post-content2"><b>Number of Players: </b> <td class="post-content">' . htmlentities(stripslashes($posts_row['post_numberofplayers'])) . '</br></tr> <td class="post-content2"><b>Production: </b> <td class="post-content">' . htmlentities(stripslashes($posts_row['post_production'])) . '</br></tr> <td class="post-content2"><b>Concept by: </b> <td class="post-content">' . htmlentities(stripslashes($posts_row['post_conceptby'])) . '</br></tr> <td class="post-content2"><b>Design by: </b> <td class="post-content">' . htmlentities(stripslashes($posts_row['post_designby'])) . '</br></tr> <td class="post-content2"><b>Art by: </b> <td class="post-content">' . htmlentities(stripslashes($posts_row['post_artby'])) . '</br></tr> <td class="post-content2"><b>Dots/Animation by: </b> <td class="post-content">' . htmlentities(stripslashes($posts_row['post_dotsanimationby'])) . '</br></tr> <td class="post-content2"><b>Mechanics by: </b> <td class="post-content">' . htmlentities(stripslashes($posts_row['post_mechanicsby'])) . '</br></tr> <td class="post-content2"><b>Music by: </b> <td class="post-content">' . htmlentities(stripslashes($posts_row['post_musicby'])) . '</br></tr> <td class="post-content2"><b>Sound by: </b> <td class="post-content">' . htmlentities(stripslashes($posts_row['post_soundby'])) . '</br></tr> <td class="post-content2"><b>Software by: </b> <td class="post-content">' . htmlentities(stripslashes($posts_row['post_softwareby'])) . '</br></tr> </td> </tr>'; } } if(!$_SESSION['signed_in']) { echo '<tr><td colspan=2>You must be <a href="signin.php">signed in</a> to comment. You can also <a href="signup.php">sign up</a> for an account.'; } else { //show reply box echo '<tr><td colspan="2"><h2>Comment on this Pinball Machine:</h2><br /> <form method="post" action="reply.php?id=' . $row['topic_id'] . '"> <textarea name="reply-content"></textarea><br /><br /> <input type="submit" value="Submit reply" /> </form></td></tr>'; } //finish the table echo '</table>'; } } } include 'footer.php'; ?> Any questions please don't hesitate to ask? Thanks in advance Dan MOD EDIT: code tags added. Hi guys Im trying to create a form which allows me to insert records into my database, and upload an image, the name of which will be stored in the database. I have the following code which inserts all the data into the db, except the image name and the image isnt uploaded either Code: [Select] <?php require_once('../Connections/pwnedbookv4.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO Games (gametitle, info, genre, releasedate, format) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($_POST['gametitle'], "text"), GetSQLValueString($_POST['info'], "text"), GetSQLValueString($_POST['genre'], "text"), GetSQLValueString($_POST['releasedate'], "date"), GetSQLValueString($_POST['format'], "text")); mysql_select_db($database_pwnedbookv4, $pwnedbookv4); $Result1 = mysql_query($insertSQL, $pwnedbookv4) or die(mysql_error()); } ?> <form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">Gametitle:</td> <td><input name="gametitle" type="text" value="" size="50" maxlength="50" /></td> </tr> <tr valign="baseline"> <?php //define a maxim size for the uploaded images in Kb define ("MAX_SIZE","100"); //This function reads the extension of the file. It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } //This variable is used as a flag. The value is initialized with 0 (meaning no error found) //and it will be changed to 1 if an errro occures. //If the error occures the file will not be uploaded. $errors=0; //checks if the form has been submitted if(isset($_POST['Submit'])) { if($_POST['Submit'] == ""){ // submit empty die ("you must include a picture"); } //reads the name of the file the user submitted for uploading $image=$_FILES['image']['name']; //if it is not empty if ($image) { //get the original name of the file from the clients machine $filename = stripslashes($_FILES['image']['name']); //get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); //if it is not a known extension, we will suppose it is an error and will not upload the file, //otherwise we will do more tests if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { //print error message echo '<h1>Unknown extension!</h1>'; $errors=1; } else { //get the size of the image in bytes //$_FILES['image']['tmp_name'] is the temporary filename of the file //in which the uploaded file was stored on the server $size=filesize($_FILES['image']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($size > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name=time().'.'.$extension; //the new name will be containing the full path where will be stored (images folder) $newname="coverart/".$image_name; //Writes the information to the database mysql_query("UPDATE Games SET cover = '$image_name' WHERE gametitle= '$gametitle'"); //we verify if the image has been uploaded, and print error instead $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; }}}} ?> <td nowrap="nowrap" align="right">Cover:</td> <td><input type="file" name="image"></td></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Info:</td> <td><input name="info" type="text" value="" size="50" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Gen </td> <td><input type="text" name="genre" value="" size="50" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Releasedate:</td> <td><input type="text" name="releasedate" value="" size="50" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Format:</td> <td><input type="text" name="format" value="" size="50" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input type="submit" value="Submit" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> Can anybody see what im missing? hi guys... I'm resizing image with some script. it works fine. but some times it gives following error and make image black. either it should not upload/resize image or it should do that for all. following is the error list i found on some images Code: [Select] Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '../../../directory/images/large/0419063.jpg' is not a valid JPEG file in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagesx() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 34 Warning: imagesy() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 35 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 182 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 183 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 76 Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 77 Warning: imagecopyresampled() expects parameter 2 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 201 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '../../../directory/images/thumb/0419063.jpg' is not a valid JPEG file in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagesx() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 34 Warning: imagesy() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 35 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 182 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 183 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 76 Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 77 Warning: imagecopyresampled() expects parameter 2 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 201 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '../../../directory/images/medium/0419063.jpg' is not a valid JPEG file in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagesx() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 34 Warning: imagesy() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 35 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 182 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 183 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 76 Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 77 Warning: imagecopyresampled() expects parameter 2 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 201 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '../../../directory/images/xlarge/0419063.jpg' is not a valid JPEG file in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagesx() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 34 Warning: imagesy() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 35 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 182 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 183 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 76 Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 77 Warning: imagecopyresampled() expects parameter 2 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 201 Hi, I have a script that currently works for uploading images and I have tried to modify it to upload PDF's and DOC's too, but I can't get it to work - it works fine with JPG or GIF. Any ideas? Thanks in advance. Code: [Select] <?php include "scripts/connect.php"; $idir = "../documents/"; // Path To Images Directory if (isset ($_FILES['fupload'])){ $randomd=rand(0000,9999); //upload the image to tmp directory $url = $_FILES['fupload']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['fupload']['type'] == "image/jpg" || $_FILES['fupload']['type'] == "image/jpeg" || $_FILES['fupload']['type'] == "image/pjpeg" || $_FILES['fupload']['type'] == "image/gif" || $_FILES['fupload']['type'] == "image/pdf" || $_FILES['fupload']['type'] == "image/doc") { $file_ext = strrchr($_FILES['fupload']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php $copy = copy($_FILES['fupload']['tmp_name'], "$idir" . "$randomd" . $_FILES['fupload']['name']); // Move Image From Temporary Location To Permanent Location } } error_reporting (E_ALL ^ E_NOTICE); if ($_POST['submit']) { $document = mysql_real_escape_string("$idir" . "$randomd" . $_FILES['fupload']['name']); $name = mysql_real_escape_string($_POST['name']); $description = mysql_real_escape_string($_POST['description']); $SQL = " INSERT INTO documents"; $SQL .= " (document, name, description) VALUES "; $SQL .= " ('$document', '$name', '$description') "; $result = mysql_db_query($db,$SQL,$cid); $last=mysql_insert_id(); if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } header("location:document-added.php?ref=$last"); exit(); } ?>[code] Hi all, I have been trying to create a thumbnail but have realised I can just resize the image instead. I have been trying to do this and have made the code below however do not know what else I need to do to upload the new image. Could someone help? Thanks <?php $filename = $_FILES['image']; $reg = "G-ZZZZ"; $width = 200; $height = 200; list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } $destination='aircraft/'.$reg."1.jpg"; $temp_file = $_FILES['image']['tmp_name']; move_uploaded_file($temp_file,$destination); ?> Code: [Select] <?php if (!isset($_SESSION['user_id'])) { echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>'; exit(); } else{ //Echo out the username of member echo('<h3 class="login"> ' . $_SESSION['username'] . '\'s Settings </h3>'); } mysqli_close($dbc); $max_no_img=3; // Maximum number of images value to be set here echo "<form method=post action=upload_project.php enctype='multipart/form-data'>"; echo "<table border='0' width='400' cellspacing='0' cellpadding='0' align=center>"; for($i=1; $i<=$max_no_img; $i++){ echo "<tr><td>images $i</td><td> <input type=file name='userfile[]' class='bginput'></td></tr>"; } echo "<tr><td colspan=2 align=center><input type=submit value='Add image'></td></tr>"; echo "</form> </table>"; function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } for($i=0; $i < 3; $i++) { $ext = findexts ($_FILES['userfile']['name'][$i]) ; $ran = rand () ; $ran2 = $ran."."; $add = "upload/"; $add = $add . $ran2.$ext; $image[$i] = $ran2.$ext ; move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $add); $new_id = $image[$i]++; $pic =$new_id++; $query = "INSERT INTO cycles (large_image1,large_image2,large_image3)". "VALUES ('$ran.$ext','$new_id','$pic')"; mysql_query($query) or die('database Query Error!'); } echo "Successfully uploaded the image"; exit; ?> Hi guys, I've been using this code to try and get image paths to upload to a database and store the image in a file called "upload/" but it doesnt seem to be working. I am also using two tables in my database and need to add into the script the user session id (user_id primary) from the current page and store it into the (user_id foreign) for the cycles tables. thanks Hi there, i want to remake a script that uploads a images in one folder to script that uploads images to folder that is equal with article id. Something like - main_folder/images/articles/$id/image.jpg ... But i don't understand how i can create it.. I don't understand how the script can know last id and move images to the folder. It's easy to add script that create folder but how the script can know latest id?.. Here is the code that process images. [It's from php fusion cms so maybe someone could not understand some things.] Thank you.. Maybe some one can give some advice how script can know latest id?. Code: [Select] if (isset($_POST['save'])) { $error = ""; $news_subject = stripinput($_POST['news_subject']); $news_cat = isnum($_POST['news_cat']) ? $_POST['news_cat'] : "0"; if (isset($_FILES['news_image']) && is_uploaded_file($_FILES['news_image']['tmp_name'])) { $image = $_FILES['news_image']; $image_name = stripfilename(str_replace(" ", "_", strtolower(substr($image['name'], 0, strrpos($image['name'], "."))))); $image_ext = strtolower(strrchr($image['name'],".")); if ($image_ext == ".gif") { $filetype = 1; } elseif ($image_ext == ".jpg") { $filetype = 2; } elseif ($image_ext == ".png") { $filetype = 3; } else { $filetype = false; } if (!preg_match("/^[-0-9A-Z_\.\[\]]+$/i", $image_name)) { $error = 1; } elseif ($image['size'] > $settings['news_photo_max_b']){ $error = 2; } elseif (!$filetype) { $error = 3; } else { $image_t1 = image_exists(IMAGES_N_T, $image_name."_t1".$image_ext); $image_t2 = image_exists(IMAGES_N_T, $image_name."_t2".$image_ext); $image_full = image_exists(IMAGES_N, $image_name.$image_ext); move_uploaded_file($_FILES['news_image']['tmp_name'], IMAGES_N.$image_full); if (function_exists("chmod")) { chmod(IMAGES_N.$image_full, 0644); } $imagefile = @getimagesize(IMAGES_N.$image_full); if ($imagefile[0] > $settings['news_photo_max_w'] || $imagefile[1] > $settings['news_photo_max_h']) { $error = 4; unlink(IMAGES_N.$image_full); } else { createthumbnail($filetype, IMAGES_N.$image_full, IMAGES_N_T.$image_t1, $settings['news_photo_w'], $settings['news_photo_h']); if ($settings['news_thumb_ratio'] == 0) { createthumbnail($filetype, IMAGES_N.$image_full, IMAGES_N_T.$image_t2, $settings['news_thumb_w'], $settings['news_thumb_h']); } else { createsquarethumbnail($filetype, IMAGES_N.$image_full, IMAGES_N_T.$image_t2, $settings['news_thumb_w']); } } } if (!$error) { $news_image = $image_full; $news_image_t1 = $image_t1; $news_image_t2 = $image_t2; } else { $news_image = ""; $news_image_t1 = ""; $news_image_t2 = ""; } } else { $news_image = (isset($_POST['news_image']) ? $_POST['news_image'] : ""); $news_image_t1 = (isset($_POST['news_image_t1']) ? $_POST['news_image_t1'] : ""); $news_image_t2 = (isset($_POST['news_image_t2']) ? $_POST['news_image_t2'] : ""); } } Hey, when a user want to upload a image this error comes up: Code: [Select] Warning: imagejpeg() [function.imagejpeg]: Unable to open 'upload/thumbs/Forest Flowers.jpg' for writing: Permission denied in /home/oppasser/domains/oppassergezocht.nl/public_html/mijn-account.php on line 195 Warning: fopen(upload/thumbs/Forest Flowers.jpg) [function.fopen]: failed to open stream: No such file or directory in /home/oppasser/domains/oppassergezocht.nl/public_html/mijn-account.php on line 197 Warning: filesize() [function.filesize]: stat failed for upload/thumbs/Forest Flowers.jpg in /home/mijn-account.php on line 198 Warning: fread(): supplied argument is not a valid stream resource in /home/mijn-account.php on line 198 Warning: fclose(): supplied argument is not a valid stream resource in /home/mijn-account.php on line 200 Warning: unlink(upload/thumbs/Forest Flowers.jpg) [function.unlink]: No such file or directory in /home/mijn-account.php on line 201 Code: [Select] imagejpeg($dimg, "$tdir" . $url); // Saving The Image $tmpName = "$tdir" . $url; $fp = fopen($tmpName, 'r'); $updimgcontent = fread($fp, filesize($tmpName)); $updimgcontent = addslashes($updimgcontent); fclose($fp); unlink($tmpName); imagedestroy($simg); // Destroying The Temporary Image imagedestroy($dimg); // Destroying The Other Temporary Image Help? |