PHP - Image Uploading By Folder Id.
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'] : ""); } } Similar TutorialsI'm trying to allow a user to upload an image, and have that image copied to an Image folder on the server When I run the code I get the success message near the bottom of the code, but the image never gets copied to the folder. I'm not sure what's causing it to not copy the image if($_POST["store"] != "") // if upload was hit { $fileExt = strrchr($_FILES['userfile']['name'], "."); // grab extension if($fileExt != ".jpg" && $fileExt != ".jpeg") // check extension { $_SESSION["badFileType"] = "You cannot upload a file of type ".$fileExt; // set error } else { $fileName = $_FILES['userfile']['name']; // set file name if(!is_uploaded_file($_FILES['userfile']['tmp_name'])) { echo "Problem: possible file upload attack!"; // set error exit(); // end } $upfile = "../Images/lg_".$category.$counter.".jpg"; // set path $newFileName = $category.$counter.".jpg"; // set new file name if(!copy($_FILES['userfile']['tmp_name'], $upfile)) // if not able to copy { echo "Problem: file could not be copied to directory!"; // set error exit(); // end } $_SESSION["badfileType"] = "File uploaded successfully!"; // set success message } } else { $_SESSION["badFileType"] = ""; // clear error } I am looking to resize the images (hight and width) after I have uploaded to a folder with php. What the bast way to do this. I am unable to resize them before I upload as I use the same picture in other areas. I'm using this code to view the image and other infomation on the database can some one point me in the right direction or show me how to change the code below. Thanks Code: [Select] <?php mysql_connect("localhost", "", "") or die(mysql_error()) ; mysql_select_db("stafflog") or die(mysql_error()) ; $data = mysql_query("SELECT * FROM ********") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { echo "<img src=http://www.web.com/productimages/" .$info['image'] . "> <br>"; echo "<b>Name:</b> ".$info['yourname'] . "<br> "; echo "<b>price:</b> ".$info['price'] . " <br>"; echo "<b>shortdes:</b> ".$info['shortdes'] . " <hr>"; } ?> Can I get some help or a point in the right direction.
I am trying to create a form that allows me to add, edit and delete records from a database.
I can add, edit and delete if I dont include the image upload code.
If I include the upload code I cant edit records without having to upload the the same image to make the record save to the database.
So I can tell I have got the code processing in the wrong way, thing is I cant seem to see or grasp the flow of this, to make the corrections I need it work.
Any help would be great!
Here is the form add.php code
<?php require_once ("dbconnection.php"); $id=""; $venue_name=""; $address=""; $city=""; $post_code=""; $country_code=""; $url=""; $email=""; $description=""; $img_url=""; $tags=""; if(isset($_GET['id'])){ $id = $_GET['id']; $sqlLoader="Select from venue where id=?"; $resLoader=$db->prepare($sqlLoader); $resLoader->execute(array($id)); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Add Venue Page</title> <link href='http://fonts.googleapis.com/css?family=Droid+Sans' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <?php $sqladd="Select * from venue where id=?"; $resadd=$db->prepare($sqladd); $resadd->execute(array($id)); while($rowadd = $resadd->fetch(PDO::FETCH_ASSOC)){ $v_id=$rowadd['id']; $venue_name=$rowadd['venue_name']; $address=$rowadd['address']; $city=$rowadd['city']; $post_code=$rowadd['post_code']; $country_code=$rowadd['country_code']; $url=$rowadd['url']; $email=$rowadd['email']; $description=$rowadd['description']; $img_url=$rowadd['img_url']; $tags=$rowadd['tags']; } ?> <h1 class="edit-venue-title">Add Venue:</h1> <form role="form" enctype="multipart/form-data" method="post" name="formVenue" action="save.php"> <input type="hidden" name="id" value="<?php echo $id; ?>"/> <div class="form-group"> <input class="form-control" type="hidden" name="id" value="<?php echo $id; ?>"/> <p><strong>ID:</strong> <?php echo $id; ?></p> <strong>Venue Name: *</strong> <input class="form-control" type="text" name="venue_name" value="<?php echo $venue_name; ?>"/><br/> <br/> <strong>Address: *</strong> <input class="form-control" type="text" name="address" value="<?php echo $address; ?>"/><br/> <br/> <strong>City: *</strong> <input class="form-control" type="text" name="city" value="<?php echo $city; ?>"/><br/> <br/> <strong>Post Code: *</strong> <input class="form-control" type="text" name="post_code" value="<?php echo $post_code; ?>"/><br/> <br/> <strong>Country Code: *</strong> <input class="form-control" type="text" name="country_code" value="<?php echo $country_code; ?>"/><br/> <br/> <strong>URL: *</strong> <input class="form-control" type="text" name="url" value="<?php echo $url; ?>"/><br/> <br/> <strong>Email: *</strong> <input class="form-control" type="email" name="email" value="<?php echo $email; ?>"/><br/> <br/> <strong>Description: *</strong> <textarea class="form-control" type="text" name="description" rows ="7" value=""><?php echo $description; ?></textarea><br/> <br/> <strong>Image Upload: *</strong> <input class="form-control" type="file" name="image" value="<?php echo $img_url; ?>"/> <small>File sizes 300kb's and below 500px height and width.<br/><strong>Image is required or data will not save.</strong></small> <br/><br/> <strong>Tags: *</strong> <input class="form-control" type="text" name="tags" value="<?php echo $tags; ?>"/><small>comma seperated vales only, e.g. soul,hip-hop,reggae</small><br/> <br/> <p>* Required</p> <br/> <input class="btn btn-primary" type="submit" name="submit" value="Save"> </div> </form> </div> </body> </html>Here is the save.php code <?php error_reporting(E_ALL); ini_set("display_errors", 1); include ("dbconnection.php"); $venue_name=$_POST['venue_name']; $address=$_POST['address']; $city=$_POST['city']; $post_code=$_POST['post_code']; $country_code=$_POST['country_code']; $url=$_POST['url']; $email=$_POST['email']; $description=$_POST['description']; $tags=$_POST['tags']; $id=$_POST['id']; if(is_uploaded_file($_FILES['image']['tmp_name'])){ $folder = "images/hs-venues/"; $file = basename( $_FILES['image']['name']); $full_path = $folder.$file; if(move_uploaded_file($_FILES['image']['tmp_name'], $full_path)) { //echo "succesful upload, we have an image!"; var_dump($_POST); if($id==null){ $sql="INSERT INTO venue(venue_name,address,city,post_code,country_code,url,email,description,img_url,tags)values(:venue_name,:address,:city,:post_code,:country_code,:url,:email,:description,:img_url,:tags)"; $qry=$db->prepare($sql); $qry->execute(array(':venue_name'=>$venue_name,':address'=>$address,':city'=>$city,':post_code'=>$post_code,':country_code'=>$country_code,':url'=>$url,':email'=>$email,':description'=>$description,':img_url'=>$full_path,':tags'=>$tags)); }else{ $sql="UPDATE venue SET venue_name=?, address=?, city=?, post_code=?, country_code=?, url=?, email=?, description=?, img_url=?, tags=? where id=?"; $qry=$db->prepare($sql); $qry->execute(array($venue_name, $address, $city, $post_code, $country_code, $url, $email, $description, $full_path, $tags, $id)); } if($success){ var_dump($_POST); echo "<script language='javascript' type='text/javascript'>alert('Successfully Saved!')</script>"; echo "<script language='javascript' type='text/javascript'>window.open('index.php','_self')</script>"; } else{ var_dump($_POST); echo "<script language='javascript' type='text/javascript'>alert('Successfully Saved!')</script>"; echo "<script language='javascript' type='text/javascript'>window.open('index.php','_self')</script>"; } } //if uploaded else{ var_dump($_POST); echo "<script language='javascript' type='text/javascript'>alert('Upload Recieved but Processed Failed!')</script>"; echo "<script language='javascript' type='text/javascript'>window.open('index.php','_self')</script>"; } } //move uploaded else{ var_dump($_POST); echo "<script language='javascript' type='text/javascript'>alert('Successfully Updated.')</script>"; echo "<script language='javascript' type='text/javascript'>window.open('index.php','_self')</script>"; } ?>Thanks in advance! Edited by hankmoody, 12 August 2014 - 05:15 PM. hello friends, while clicking the form all the information goes to database, I have one image upload field, when cliking the submit button, i would like 'image name' to go in database and file to go in /upload folder, i have tried this for hours and gave up, if anyone help me in this, i would be very greatful 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 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 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? 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> Good day: Im trying to display an image from a folder and the image name is retrieved by a query. The query is getting the image name all right but the image is not displaying. This is the code im using for the image display Code: [Select] <?php $aid = 1; $connection = mysql_connect("localhost", "username", "password"); mysql_select_db("articles", $connection); $query="SELECT imagename, description FROM articles_description WHERE id='$aid'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table width ="1000" border="1" cellspacing="2" cellpadding="2"> </tr> <?php $j=0; while ($j < $num) { $f8=mysql_result($result,$i,"description"); $f9=mysql_result($result,$i,"imagename") ?> <tr> <td valign="top"> <img src="images/'.$f9.'; ?>" alt="" name="picture" width="100" height="100" border="1" /></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f8; ?></font></td> </tr> <tr> </tr> <?php $j++; } ?> Any help will be appreciated If I upload this script in /www/ads/insert/image/ it works fine If I upload it in /www/ads/insert/ it does not work It says PHP could not open /new/ to upload image Code: [Select] <? $target_path = 'images/new/'; $image_name = 'myself.gif'; if( imagejpeg( $tmp_img, "{$target_path}{$image_name}" ) ){ print"image uploaded!"; } ?> I think because PHP only allows to upload images 1 folder deep!!! Why? How do I solve this? I want to create different folders for each group of images Hello
I am new here, and so i am to php.. i have a small question - i think anyone here could help me, im sure :-)
I have a php-gallery running locally on my desktop (using xampp), the gallery just shows images from a directory where a webcam saves its pictures in it (the gallery is named "ubergallery" - maybe anyone knows this gallery).
Now i really would like to have following option:
- A Button on the thumbnail called "delete" - when clicking on it, the picture should get replaced with another, predefined, placeholder-picture. I really hope somebody here can help me ! Thank you so much for your time !
I have attached the files!
Attached Files
UberGallery.php 37.81KB
0 downloads
index.php 2.81KB
0 downloads
index.php 663bytes
0 downloads Hey guys - I have some code that pulls an image out of a folder and displays it on the page. The problem is, there won't always be an image to display in which case I'd rather the code not even display. Here's my code so far: Code: [Select] <tr><td><a href="images/uploads/<?php echo $row['loc_id']; ?>_1.jpg"><img id="morephoto" src="images/uploads/thumbs/<?php echo $row['loc_id']; ?>_1thb.jpg" /></a></td></tr> The images are renamed on upload to have the id number for that row appended to the front of the file name and that is how I'm calling them back in. I know I need to write an if statement that contains the code from the <tr> to the </tr> to display if the image exists, the problem is, since there isn't a field for this in the database, I don't know how to check it? I'm still a noob so I appreciate any help that is offered. Thanks! 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] This is my PHP code which uploads the image from a html form. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Upload a Photograph</title> <link rel="stylesheet" href="uploadify.css" type="text/css" /> <script language="JavaScript" type="text/javascript"> <!-- function breakout_of_frame() { // see http://www.thesitewizard.com/archive/framebreak.shtml // for an explanation of this script and how to use it on your // own website if (top.location != location) { top.location.href = "http:/noltest.lib.siu.edu/drupal/blincore?file='"+fileObj.name+"'" ; } } --> </script> <script type="text/javascript" src="jquery-1.3.2.min.js"></script> <script type="text/javascript" src="jquery.uploadify.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#fileUpload").fileUpload({ 'uploader': 'uploader.swf', 'cancelImg': 'cancel.png', 'script': 'upload.php', 'folder': 'downloads', 'fileDesc': 'Image Files', 'fileExt': '*.jpeg,*.jpg,*.tif,*.tiff,*.gif,*.png', 'checkScript': 'check.php', 'multi': false, 'displayData': 'speed', 'onComplete': function(event, queueID, fileObj, response, data) { $('#filesUploaded').append ('One Image Uploaded successfully (<a href='+fileObj.filePath+'>'+fileObj.name+'</a>)</br></br> <FORM METHOD=POST ACTION="http://nol.lib.siu.edu/drupal/dublincore"> <INPUT NAME=filename value="'+fileObj.name+'"> <INPUT TYPE=submit VALUE="NEXT" ></FORM ><br>');} }); }); </script> </head> <body style="background: #f1ede0 url(http://nol.lib.siu.edu//sites/all/themes/admire_grunge/images/bg2.jpg) repeat fixed top center;"> <h2>Single Photograph Upload</h2> <div id="fileUpload">Issue with your javascript</div> <a href="javascript:$('#fileUpload').fileUploadStart()">Start Upload</a> | <a href="javascript:$('#fileUpload').fileUploadClearQueue()">Clear Queue</a> <p></p> <p><div id="filesUploaded"></div></p> </body> </html> problem: when i try to upload image from the desktop which contains image named (test.jpg) , this test.jpg is not shown when browsing to select the image file. any advice... 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 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 |