PHP - Document Upload Form
how do I make document upload fields like the ones that are on this website where there is a link at the bottom to make another field appear, or make it so that a new field automatically appears when the first one has info in it. Does this make sense? and also how would i make these submit with the form seeing as that they would have different field names, wouldn't they?
Similar TutorialsThis topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=334078.0 so I want to know how I could upload a document associated with an event.......with a form upload.......but where do I store it at and make it display in the view page for the event......? Hi everyone. I have been looking for a PHP upload script that handles various different document types like PDF, DOC and XLS. So far all I have found is image upload scripts. Can anyone point me in the right direction? I would be most greatful. Thank you! Hello, I had created a form for users to upload their resumes (only word documents & 1 MB allowed as size), then email it after its been successfully uploaded. Any help? Thanks in advance Hi guys, I have created a php script (with alot of help from others) that allows me to have a login area on my website. When the user logs onto their page - they obviously cannot see the others profile. My next task is to be able to upload PDF documents to appear on their profiles. The PDF's will be specific to them. The main problems I have a 1/ They cannot be able to view any PDF but their own. 2/ How do I create a form that knows where to send and display the link? I guess it is using the user id & name etc? I will not actually be the one uploading the files else I would just sit and tediously link each form to each profile. This must be done by my secretary via a file upload form that I will password protect. I basically want her to be able to log in and be presented with a document upload form. The form will have a dropdown list of the clients name and a document upload part. From uploading it will then appear on the users page. If anyone could help it would be amazing! I am fairly new to PHP although am getting better with my understanding. Hopefully I will become as good as you lot one day! Cheers in advance Hi- the code below lets me upload a CSV file to my database if I have 1 field in my database and 1 column in my CSV. I need to add to my db "player_id" from the CVS file and "event_name" and "event_type" from the form... any ideas??? here's the code: Code: [Select] <?php $hoststring =""; $database = ""; $username = ""; $password = ""; $makeconnection = mysql_pconnect($hoststring, $username, $password); ?> <?php ob_start(); mysql_select_db($database, $makeconnection); $sql_get_players=" SELECT * FROM tabel ORDER BY player_id ASC"; // $get_players = mysql_query($sql_get_players, $makeconnection) or die(mysql_error()); $row_get_players = mysql_fetch_assoc($get_players); // $message = null; $allowed_extensions = array('csv'); $upload_path = '.'; //same directory if (!empty($_FILES['file'])) { if ($_FILES['file']['error'] == 0) { // check extension $file = explode(".", $_FILES['file']['name']); $extension = array_pop($file); if (in_array($extension, $allowed_extensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'], $upload_path.'/'.$_FILES['file']['name'])) { if (($handle = fopen($upload_path.'/'.$_FILES['file']['name'], "r")) !== false) { $keys = array(); $out = array(); $insert = array(); $line = 1; while (($row = fgetcsv($handle, 0, ',', '"')) !== FALSE) { foreach($row as $key => $value) { if ($line === 1) { $keys[$key] = $value; } else { $out[$line][$key] = $value; } } $line++; } fclose($handle); if (!empty($keys) && !empty($out)) { $db = new PDO( 'mysql:host=host;dbname=db', 'user', 'pw'); $db->exec("SET CHARACTER SET utf8"); foreach($out as $key => $value) { $sql = "INSERT INTO `table` (`"; $sql .= implode("`player_id`", $keys); $sql .= "`) VALUES ("; $sql .= implode(", ", array_fill(0, count($keys), "?")); $sql .= ")"; $statement = $db->prepare($sql); $statement->execute($value); } $message = '<span>File has been uploaded successfully</span>'; } } } } else { $message = '<span>Only .csv file format is allowed</span>'; } } else { $message = '<span>There was a problem with your file</span>'; } } ob_flush();?> <!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>CSV File Upload</title> </head> <body> <form class="form" action="" method="post" enctype="multipart/form-data"> <h3>Select Your File</h3> <p><?php echo $message; ?></p> <input type="file" name="file" id="file" size="30" /> <br/> <label>Event Name:</label><input name="event_name" type="text" value="" /> <br/> <label>Event Type:</label><input name="event_type" type="text" value="" /> <br/> <input type="submit" id="btn" class="button" value="Submit" /> </form> <br/> <h3>Results:</h3> <?php do { ?> <p><?php echo $row_get_players['player_id'];?></p> <?php } while ($row_get_players = mysql_fetch_assoc($get_players)); ?> </body> </html> I've been using php for a while now to create forms, up until now i've always transmitted the form data to a new php document that then processes them. I wanna take this to the next level and start trying to process the data within the same document. I know this has something to do with checking if the submit button is pressed and then processing the submitted data but thats about as far as my knowledge goes. Can anyone help me out on how i can achieve this type of thing. The reason is that i've found a way to execute php code within a joomla 1.6 environment without having to use the iframe option. I know the iframe option may be easier in a way of doing things but its out of the question. The final fase of the php will output code that will trigger a specific joomla plugin to do some specific action. If i pull a php document via an iframe the plugin doesnt trigger as it only gets triggered after the joomla "afterRender" (or something" has executed. If i use the iframe option then that rendering never gets used so the plugin doesnt get triggered. So in a nutshell, i wanna create forms that submit data and that data gets processed in the same document (in this case joomla article). How do i go about doing this. Hi, I want to check conditions for what is being uploaded. Basically I want to allow users to upload many XSD schema and XML file, so each complete upload is when user gives an 1 XSD file for 1 XML file to validate against, then the successful files are uploaded to db. first page:(numUpload.html) ======= <input type="text" name="numUploads"> to ask how many upload XSD:XML pairs they want, press SUBMIT goes to uploadForm.php eg: if user types 2, then we have four upload forms (upload form for 1st XSD, upload form for 1st XML file; upload form for 2nd XSD file, upload form for 2nd XML file) second page(uploadForm.php): ===================== for loop to create each uploaded pair then the validated XML (using the XSD of course) have their filenames inserted into db press SUBMIT (goes to upload.php to validate each before entering the validated XML filenames to db) You see, I want to have it organized where first upload form for first XSD:XML pair must be .xsd and second form of pair must be .xml In short, this is what I need help to figure out how to code (the conditions to check before uploading): ========================================== *1)for a given upload form pair, the first upload form only accepts .xsd, the second form only accepts .xml 2)no duplicate XML files allowed (XSD is ok) 3)if user uploads an .xsd, there must be an .xml *eg for point 1)XSD#1[_________] (Browse...) XML#1[_________] (Browse...) ------------------------------------------ XSD#2 [_________] (Browse...) XML#2 [_________] (Browse...) Above is the upload forms I "drew", so I want to keep each pair as such where the first upload form for a given pair can only accept .xsd files and second form of a given pair of upload forms only accepts .xml files AND NO duplicate .xml files at all! Any help much appreciated! anybody know of any tutorials on how to make an upload to server form? ive been searching google for hours and it seems as though all the scripts on there just upload to php temp. i need to make it goto a specific folder on the server. thanks hi there, Im running into a dead brainer here. I want to allow users to upload an article, and in this article have text and an image. So the article will have a title, image and content. Hard to describe, but my problem is this: Uploading these from a form, so that in the database they appear in just one row together, so the image and text is linked to the title of the article. How could I go about doing this, as the ID's of the articles will automatically be generated, im not sure how i could code is so that all of these are specific to their id's. I have this image upload script already from another use site i have developed and have start to re work it, but wondering how i could adapt this with a form with more than just the image upload in it. Sorry if sounds bit complicated, hard to word what im thinking thanks in advance <?php require("include/conn.php"); include "include/session.php"; // Check to see if the type of file uploaded is a valid image type function is_valid_type($file) { $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif"); if (in_array($file['type'], $valid_types)) return 1; return 0; } function showContents($array) { echo "<pre>"; print_r($array); echo "</pre>"; } $TARGET_PATH = "images/"; // Get POSTed variables $image = $_FILES['image']; $image['name'] = mysql_real_escape_string($image['name']); $TARGET_PATH .= $image['name']; // Make sure all the fields from the form have inputs if ($image['name'] == "" ) { $_SESSION['error'] = "All fields are required"; header("Location: addvox.php"); exit; } // Verify file is an image if (!is_valid_type($image)) { $_SESSION['error'] = "You must upload a jpeg, gif, or bmp"; header("Location: addvox.php"); exit; } // move file into the directory and the path name into the database if (move_uploaded_file($image['tmp_name'], $TARGET_PATH)) { $sql = "UPDATE vox SET image = '" . $image['name'] . //where id = 'VOX_ID'; $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error()); header("Location: user-page.php"); exit; } else { $_SESSION['error'] = "Could not upload file. Check read/write persmissions on the directory"; exit; } ?> What i have here is a code for uploading files to specified folder. I have a problem which i cant found in code. All uploaded files get a new name with many numbers. I dont want this because i cant collect files for gallery because filenames are different as uploaded ones. Example: I have a file biggreen.gif on my computer. I upload it trough this form, and when i check that file in folder i uploaded to, the name is 1299616037_biggreen.gif. Help me please. Code: [Select] <?php //Load the settings require_once("settings.php"); $message = ""; //Has the user uploaded something? if(isset($_FILES['file'])) { $target_path = Settings::$uploadFolder; $target_path = $target_path . time() . '_' . basename( $_FILES['file']['name']); //Check the password to verify legal upload if($_POST['password'] != Settings::$password) { $message = "Invalid Password!"; } else { //Try to move the uploaded file into the designated folder if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) { $message = "The file ". basename( $_FILES['file']['name']). " has been uploaded"; } else{ $message = "There was an error uploading the file, please try again!"; } } //Clear the array unset($_FILES['file']); } if(strlen($message) > 0) { $message = '<p class="error">' . $message . '</p>'; } /** LIST UPLOADED FILES **/ $uploaded_files = ""; //Open directory for reading $dh = opendir(Settings::$uploadFolder); //LOOP through the files while (($file = readdir($dh)) !== false) { if($file != '.' && $file != '..') { $filename = Settings::$uploadFolder . $file; $parts = explode("_", $file); $size = formatBytes(filesize($filename)); $added = date("m/d/Y", $parts[0]); $origName = $parts[1]; $filetype = getFileType(substr($file, strlen($file) - 3)); $uploaded_files .= "<ul class=\"list\"><li class=\"$filetype\"><a href=\"$filename\">$origName</a> $size - $added</li></ul>\n"; } } closedir($dh); if(strlen($uploaded_files) == 0) { $uploaded_files = "<ul class=\"list\"><li><em>No files found</em></li></ul>"; } function getFileType($extension) { $images = array('jpg', 'gif', 'png', 'bmp'); $docs = array('txt', 'rtf', 'doc'); $apps = array('zip', 'rar', 'exe'); if(in_array($extension, $images)) return "Images"; if(in_array($extension, $docs)) return "Documents"; if(in_array($extension, $apps)) return "Applications"; return ""; } function formatBytes($bytes, $precision = 2) { $units = array('B', 'KB', 'MB', 'GB', 'TB'); $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); $bytes /= pow(1024, $pow); return round($bytes, $precision) . ' ' . $units[$pow]; } ?> I tried to add a second file upload to my previously properly functioning form, but after adding it, now when I submit the form, it submits the data twice. It appears to be submitting the file right on the first insert, but on the second insert, the second image is not inserted, but just blank. Can anyone help me figure out why? I must have done something wrong in my insert statement or second file statement. Here is the page itself which contains the form: http://midwestcreativeconsulting.com/jhrevell/add/ And below is my insert page: Code: [Select] <?php $dbhost = 'localhost'; $dbuser = 'username'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'jhrevell_jewelry'; mysql_select_db($dbname); $name = $_POST['name']; $metal = $_POST['metal']; $desc = $_POST['desc']; $item_no = $_POST['item_no']; $cut = $_POST['cut']; $color = $_POST['color']; $carats = $_POST['carats']; $clarity = $_POST['clarity']; $size = $_POST['size']; $type = $_POST['type']; $other = $_POST['other']; $total = $_POST['total']; $certificate = $_POST['certificate']; $value = $_POST['value']; //if ((($_FILES["file"]["type"] == "image/gif") //|| ($_FILES["file"]["type"] == "image/jpeg") //|| ($_FILES["file"]["type"] == "image/pjpeg")) //&& ($_FILES["file"]["size"] < 20000)) // { 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 $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); //echo "Stored in: " . "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]; $image = $_FILES["file"]["name"]; $query = "INSERT INTO gallery VALUES ('', '$cut', '$color', '$carats', '$clarity', '$size', '$metal', '$other', '$total', '$certificate', '$value', '$image', '$name', '$desc', '$item_no', '$type', '$image2')"; $query_res = mysql_query($query) or die(mysql_error()); } } //} // IMAGE 2 // //if ((($_FILES["file"]["type"] == "image/gif") //|| ($_FILES["file"]["type"] == "image/jpeg") //|| ($_FILES["file"]["type"] == "image/pjpeg")) //&& ($_FILES["file"]["size"] < 20000)) // { if ($_FILES["file2"]["error"] > 0) { echo "Return Code: " . $_FILES["file2"]["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["file2"]["name"])) { echo $_FILES["file2"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file2"]["tmp_name"], "upload/" . $_FILES["file2"]["name"]); //echo "Stored in: " . "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]; $image2 = $_FILES["file2"]["name"]; $query = "INSERT INTO gallery VALUES ('', '$cut', '$color', '$carats', '$clarity', '$size', '$metal', '$other', '$total', '$certificate', '$value', '$image', '$name', '$desc', '$item_no', '$type', '$image2')"; $query_res = mysql_query($query) or die(mysql_error()); } } //} echo '<script language="Javascript">'; echo 'window.location="http://midwestcreativeconsulting.com/jhrevell/collections"'; echo '</script>'; ?> Can anyone see what could be causing it to insert the record twice? Hey guys. I'm using this script to handle file (picture) uploads at the moment, and it works fine. Problem is though, I need to changeit to a multiple upload form (with 10 uploads per submit) and I dont know how to do it. I think ... I need to change this "<input type="file" name="image" >" to an array ... and put a "for each" loop or something somewhere ... but I really don't know what I am doing. Can someone please help? Thanks Gem <?php include ("includes/dbconnect120-gem.php"); //define a maxim size for the uploaded images define ("MAX_SIZE","500"); // define the width and height for the thumbnail // note that theese dimmensions are considered the maximum dimmension and are not fixed, // because we have to keep the image ratio intact or it will be deformed define ("WIDTH","150"); define ("HEIGHT","100"); // this is the function that will create the thumbnail image from the uploaded image // the resize will be done considering the width and height defined, but without deforming the image function make_thumb($img_name,$filename,$new_w,$new_h) { //get image extension. $ext=getExtension($img_name); //creates the new image using the appropriate function from gd library if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) $src_img=imagecreatefromjpeg($img_name); if(!strcmp("png",$ext)) $src_img=imagecreatefrompng($img_name); //gets the dimmensions of the image $old_x=imageSX($src_img); $old_y=imageSY($src_img); // next we will calculate the new dimmensions for the thumbnail image // the next steps will be taken: // 1. calculate the ratio by dividing the old dimmensions with the new ones // 2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable // and the height will be calculated so the image ratio will not change // 3. otherwise we will use the height ratio for the image // as a result, only one of the dimmensions will be from the fixed ones $ratio1=$old_x/$new_w; $ratio2=$old_y/$new_h; if($ratio1>$ratio2) { $thumb_w=$new_w; $thumb_h=$old_y/$ratio1; } else { $thumb_h=$new_h; $thumb_w=$old_x/$ratio2; } // we create a new image with the new dimmensions $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); // resize the big image to the new created one imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // output the created image to the file. Now we will have the thumbnail into the file named by $filename if(!strcmp("png",$ext)) imagepng($dst_img,$filename); else imagejpeg($dst_img,$filename); //destroys source and destination images. imagedestroy($dst_img); imagedestroy($src_img); } // 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; if(isset($_POST['submit1']) && !$errors) { $sqlalbum="INSERT INTO album (album_name) VALUES ('$_POST[newalbumname]')"; mysql_query($sqlalbum) or die ('Error, album_query failed : ' . mysql_error()); } // checks if the form has been submitted if(isset($_POST['Submit'])) { //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, print an error message //and will not upload the file, otherwise we continue if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) { 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=getimagesize($_FILES['image']['tmp_name']); $sizekb=filesize($_FILES['image']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($sizekb > 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="uploads/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); //we verify if the image has been uploaded, and print error instead if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; } else { // the new thumbnail image will be placed in images/thumbs/ folder $thumb_name='uploads/thumbs/thumb_'.$image_name; // call the function that will create the thumbnail. The function will get as parameters //the image name, the thumbnail name and the width and height desired for the thumbnail $thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT); }} }} //If no errors registred, print the success message and show the thumbnail image created if(isset($_POST['Submit']) && !$errors) { $album = $_POST['album']; $query = "INSERT INTO upload (name, path, album_id, thumbpath ) ". "VALUES ('$image_name', '$newname' , '$album', '$thumb_name')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); echo "<h1>Thumbnail created Successfully!</h1>"; echo '<img src="'.$thumb_name.'">'; } ?> <!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>Untitled Document</title> </head> <body> <form name="newalbum" method="post" action=""> <input name="newalbumname" type="text" size="30" maxlength="30" value="<?php echo $newalbumname; ?>" /> <input type="submit" name="submit1" value="Create Album" /> </form> <br /> <form name="newad" method="post" enctype="multipart/form-data" action=""> <table> <tr><td><select name="album"> <option value="select" selected="selected" >-Albums-</option> <?php $asql="select * from album order by album_id DESC"; $aresult=mysql_query($asql) or die(mysql_error());; while($arow=mysql_fetch_array($aresult)) { $album_id=$arow['album_id']; $album_name=$arow['album_name']; ?> <option value="<?php echo $album_id; ?>"><?php echo $album_name; ?></option> <?php } ?> </select> <tr><td><input type="file" name="image" ></td></tr> <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr> </table> </form> </body> </html> In the past I always combine my PHP Form Processing Code with my HTML Forms in one script, and when the User clicks "Submit", the Form/Page reloads itself. Is it possible to load an Upload Form to itself? Something like this... Code: [Select] <form enctype="multipart/form-data" action="" method="post"> Debbie Hi People, I have this problem, i have created an upload form which includes some text fields and also an image upload which then gets sent to a server. I haven't yet got any validation or sanitisation on there at the moment. Im abit new to PHP and can code beginners stuff really, could someone give us some help with this please! addproduct.php - This is my form Code: [Select] <table width="300" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td><form enctype="multipart/form-data" name="form1" method="post" action="insert_add.php"> <table width="100%" border="0" cellspacing="1" cellpadding="3"> <tr> <td width="200"><b>Model</b></td> <td width="10">:</td> <td width="400"><input name="model" type="text" id="model" size="28"></td> </tr> <tr> <td><b>Product</b></td> <td>:</td> <td><input name="product" type="text" id="product" size="28"></td> </tr> <tr> <td><b>Description</b></td> <td>:</td> <td><textarea rows="5" cols="21" type="text" name="description" id="description"></textarea></td> </tr> <tr> <td><b>Price</b></td> <td>:</td> <td><input name="price" type="text" id="price" size="28"></td> </tr> <tr> <td><b>Image:</b></td> <td>:</td> <td><input type="file" name="photo"></td> </tr> <tr> <tr> <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form> </td> </tr> </table> insert_add.php - This is a page which uploads contents to server <?php $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //This is the directory where images will be saved $target = "images/"; $target = $target . basename( $_FILES['photo']['name']); // Get values from form $model=$_POST['model']; $product=$_POST['product']; $description=$_POST['description']; $price=$_POST['price']; $pic=($_FILES['photo']['name']); // Insert data into mysql $sql="INSERT INTO $tbl_name(model, product, description, price, photo)VALUES('$model', '$product', '$description', '$price', '$pic')"; $result=mysql_query($sql); if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "<center>The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory</center>"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } // close connection mysql_close(); ?> Any help with coding would be greatfully appreciated. Hey, im trying to hide a form for a upload script. but it will just look like this (see picture). its for a school project, here is the code Code: [Select] <div class="brick-left"> <?php $brugernavn = $_SESSION['brugernavn']; if ($_SESSION['brugernavn']) { $result = mysql_query("SELECT * FROM bruger WHERE brugernavn='$brugernavn'"); while ($row = mysql_fetch_array($result)) { $admin = $row['admin']; } if ($admin == 1){ echo"<center>"; echo"<form action=" . print $_SERVER["PHP_SELF"] . "method='post' enctype='multipart/form-data'>"; echo"<p><input type='hidden' name='contxt' value='upload'>"; echo"<input type='hidden' name='userId' value='123'>"; echo"<input type='file' name='upFile'></p>"; echo"<p><button type='submit'>Upload</button></p>"; echo"</form>"; } } ?> <?php print $message ?> </center> </div> Hi, I have been trying to create a site where you can list multiple items with a picture for each but I can't get the upload form working. Here's what I've got: <?php include "/home/a9653716/public_html/header.inc"; ?> <body> <table border="0" width="100%"><tr> <td valign="top" width="800"> <?php echo "<div id='content'>"; echo "<h2 div id='title'>"; echo "Create a listing"; echo "</h2>"; //////content////////////////////////// if($_SESSION['uid']){ $id = mss($_POST['id']); $no_w =($_POST['want']); $no_o =($_POST['offer']); $wantbtn = ($_POST['addwantbtn']); $offerbtn = ($_POST['addofferbtn']); if ($wantbtn) echo "Want <br />"; $no_want = ($_POST['no_want']); $no_offer = ($_POST['no_offer']); if (!$no_w){ if ($no_want){ $no_w = $no_want; }else $no_w = 3; } if (!$no_o){ if ($no_offer){ $no_o = $no_offer; }else $no_o = 3; } if ($no_o > 20){ $no_o = 20; } if ($no_w > 20){ $no_w = 20; } $offerid = 1; $wantid = 1; $addofferlimit = 20 - $no_o + 1; $addwantlimit = 20 - $no_w + 1; $addoffer = 1; $addwant = 1; $addmorewants = ($_POST['addmorewants']); $addmoreoffers = ($_POST['addmoreoffers']); if ($wantbtn){ $no_w = $addmorewants; } if ($offerbtn){ $no_o = $addmoreoffers; } if ($id) { $sql = "SELECT * FROM `item_sub_cats` WHERE `id`='" . $id . "'"; $res = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($res) == 0) { echo "The category you are trying to create a listing on, does not exist!\n"; } else { $row1 = mysql_fetch_assoc($res); if (!$_POST['submit']) { echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<form method=\"post\" action=\"./create_listing.php\">\n"; echo "<tr><td>Sub Category</td><td><select name=\"cat\">\n"; $sql2 = "SELECT * FROM `item_cats`"; $res2 = mysql_query($sql2); while ($row = mysql_fetch_assoc($res2)) { $sql3 = "SELECT * FROM `item_sub_cats` WHERE `cid`='" . $row['id'] . "'"; $res3 = mysql_query($sql3) or die(mysql_error()); echo "<option value=\"0\">" . $row['name'] . "</option>\n"; while ($row2 = mysql_fetch_assoc($res3)) { $selected = ($row2['id'] == $id) ? " SELECTED" : ""; echo "<option value=\"" . $row2['id'] . "\"" . $selected . "> " . $row2['name'] . "</option>\n"; } } echo "</select></td></tr>\n"; echo "<tr><td>Listing Title</td><td><input type=\"text\" name=\"title\" size=\"53\"></td></tr>\n"; ?> <script>edToolbar('message'); </script> <?php echo "<tr><th colspan='2'><b>What you have to offer!</b><br /><br />Change to <select name='addmoreoffers'>"; echo "<option>1</option>"; echo "<option>2</option>"; echo "<option>3</option>"; echo "<option>4</option>"; echo "<option>5</option>"; echo "<option>6</option>"; echo "<option>7</option>"; echo "<option>8</option>"; echo "<option>9</option>"; echo "<option>10</option>"; echo "<option>11</option>"; echo "<option>12</option>"; echo "<option>13</option>"; echo "<option>14</option>"; echo "<option>15</option>"; echo "<option>16</option>"; echo "<option>17</option>"; echo "<option>18</option>"; echo "<option>19</option>"; echo "<option>20</option>"; echo "</select> item(s) <input type='submit' value='Go' name='addofferbtn'><br /></th></tr>"; //offer while loop// while ($offerid <= $no_o){ echo "<tr><td>Item $offerid</td><td><input type='textbox' value='title' size='40' name='offer$offerid'> <input type='textbox' value='pts' size='7' name='offer" . $offerid . "pts'></td></tr>"; echo "<tr><td></td><th colspan='2'><textarea cols='37' rows='5' name='offer" . $offerid . "desc'></textarea></th></tr>"; echo "<tr><td></td><td><input type='file' size='27' name='offer" . $offerid . "img'></td></tr>"; $offerid ++; } //end offer while loop// //want while loop// echo "<tr><th colspan='2'><b>What you want!</b><br /><br />Change to <select>"; echo "<option>1</option>"; echo "<option>2</option>"; echo "<option>3</option>"; echo "<option>4</option>"; echo "<option>5</option>"; echo "<option>6</option>"; echo "<option>7</option>"; echo "<option>8</option>"; echo "<option>9</option>"; echo "<option>10</option>"; echo "<option>11</option>"; echo "<option>12</option>"; echo "<option>13</option>"; echo "<option>14</option>"; echo "<option>15</option>"; echo "<option>16</option>"; echo "<option>17</option>"; echo "<option>18</option>"; echo "<option>19</option>"; echo "<option>20</option>"; echo "</select> item(s) <input type='submit' value='Go' name='addwantbtn'><br /></th></tr>"; while ($wantid <= $no_w){ echo "<tr><td>Item $wantid</td><td><input type='textbox' size='40' value='title' name='want" . $wantid . "title'> <input type='textbox' value='pts' size='7' name='want" . $wantid . "pts'></td></tr>"; echo "<tr><td></td><th colspan='2'><textarea cols='37' rows='5' name='want" . $wantid . "desc'></textarea></th></tr>"; echo "<tr><td></td><td><input type='file' size='27' name='want" . $wantid . "img'></td></tr>"; $wantid ++; } //end want while loop// echo "<tr><td>Other Details</td><th colspan='2'><textarea cols='50' rows='10' id=\"message\" name=\"message\"></textarea></th></tr>\n"; echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Create Listing\"></td></tr>\n"; echo "</form></table>\n"; } else { $cat = mss($_POST['cat']); $title = mss($_POST['title']); $details = mss($_POST['message']); if ($cat && $title && $details) { $sql = "SELECT * FROM `item_sub_cats` WHERE `id`='" . $cat . "'"; $res = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($res) == 0) { echo "This sub category does not exist!\n"; } else { $row = mysql_fetch_assoc($res); if (strlen($title) < 3 || strlen($title) > 32) { echo "The title must be between 3 and 32 characters!\n"; } else { if (strlen($details) < 3 || strlen($details) > 10000) { echo "The message must be between 3 and 10,000 characters!\n"; } else { $date = date("m-d-y") . " at " . date("h:i:s"); $time = time(); $sql2 = "INSERT INTO `listing_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`,) VALUES('" . $cat . "','" . $title . "','" . $_SESSION['uid'] . "','" . $date . "','" . $time . "','" . $details . "')"; $res2 = mysql_query($sql2) or die(mysql_error()); $tid = mysql_insert_id(); topic_go($tid); } } } } else { } } } } else { if (!$_POST['submit']) { echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<form method=\"post\" action=\"./create_listing.php\">\n"; echo "<tr><td>Sub Category</td><td><select name=\"cat\">\n"; $sql2 = "SELECT * FROM `item_cats`"; $res2 = mysql_query($sql2) or die(mysql_error()); while ($row = mysql_fetch_assoc($res2)) { $sql3 = "SELECT * FROM `item_sub_cats` WHERE `cid`='" . $row['id'] . "'"; $res3 = mysql_query($sql3) or die(mysql_error()); echo "<option value=\"0\">" . $row['name'] . "</option>\n"; while ($row2 = mysql_fetch_assoc($res3)) { $selected = ($row2['id'] == $id) ? " SELECTED" : ""; echo "<option value=\"" . $row2['id'] . "\"" . $selected . "> " . $row2['name'] . "</option>\n"; } } echo "</select></td></tr>\n"; echo "<tr><td>Listing Title</td><td><input type=\"text\" name=\"title\" size=\"53\"></td></tr>\n"; ?> <script>edToolbar('message'); </script> <?php echo "<tr><th colspan='2'><b>What you have to offer!</b><br /><br />Change to <select name='addmoreoffers'>"; echo "<option>1</option>"; echo "<option>2</option>"; echo "<option>3</option>"; echo "<option>4</option>"; echo "<option>5</option>"; echo "<option>6</option>"; echo "<option>7</option>"; echo "<option>8</option>"; echo "<option>9</option>"; echo "<option>10</option>"; echo "<option>11</option>"; echo "<option>12</option>"; echo "<option>13</option>"; echo "<option>14</option>"; echo "<option>15</option>"; echo "<option>16</option>"; echo "<option>17</option>"; echo "<option>18</option>"; echo "<option>19</option>"; echo "<option>20</option>"; echo "</select> item(s) <input type='submit' value='Go' name='addofferbtn'><br /></th></tr>"; //offer while loop// while ($offerid <= $no_o){ $offername = "offer" . "$offerid"; echo "<tr><td>Item $offerid</td><td><input type='textbox' value='title' size='40' name='$offername'> <input type='textbox' value='pts' size='7' name='offer" . $offerid . "pts'></td></tr>"; echo $offername; echo "<tr><td></td><th colspan='2'><textarea cols='37' rows='5' name='offer" . $offerid . "desc'></textarea></th></tr>"; echo "<tr><td></td><td><input type='file' size='27' name='offer" . $offerid . "img'></td></tr>"; $offerid ++; } //end offer while loop// //want while loop// echo "<tr><th colspan='2'><b>What you want!</b><br /><br />Change to <select name='addmorewants'>"; echo "<option>1</option>"; echo "<option>2</option>"; echo "<option>3</option>"; echo "<option>4</option>"; echo "<option>5</option>"; echo "<option>6</option>"; echo "<option>7</option>"; echo "<option>8</option>"; echo "<option>9</option>"; echo "<option>10</option>"; echo "<option>11</option>"; echo "<option>12</option>"; echo "<option>13</option>"; echo "<option>14</option>"; echo "<option>15</option>"; echo "<option>16</option>"; echo "<option>17</option>"; echo "<option>18</option>"; echo "<option>19</option>"; echo "<option>20</option>"; echo "</select> item(s) <input type='submit' value='Go' name='addwantbtn'><br /></th></tr>"; while ($wantid <= $no_w){ $wantname = "want" . "$wantid"; echo "<tr><td>Item $wantid</td><td><input type='textbox' size='40' value='title' name='$wantname'> <input type='textbox' value='pts' size='7' name='want" . $wantid . "pts'></td></tr>"; echo "<tr><td></td><th colspan='2'><textarea cols='37' rows='5' name='want" . $wantid . "desc'></textarea></th></tr>"; echo "<tr><td></td><td><input type='file' size='27' name='want" . $wantid . "img'></td></tr>"; $wantid ++; } //end want while loop// echo "<tr><td>Other Details</td><th colspan='2'><textarea cols='50' rows='10' id=\"message\" name=\"message\"></textarea></th></tr>\n"; echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Create Listing\"></td></tr>\n"; echo "<input type='hidden' name='no_offer' value='$no_o'>"; echo "<input type='hidden' name='no_want' value='$no_w'>"; echo "</form></table>\n"; } else { $cat = mss($_POST['cat']); $title = mss($_POST['title']); $details = mss($_POST['message']); $o_title_count = 1; $filled_o = 1; $offer_no_values=1; $w_title_count = 1; $filled_w = 1; $want_no_values=1; while ($filled_o && $filled_o != "title"){ $o_title_count = "offer" . "$offer_no_values"; $filled_o = ($_POST["$o_title_count"]); $offer_no_values++; } $offer_no_values=$offer_no_values-2; echo "Number of offer titles:" . $offer_no_values . "<br />"; while ($filled_w && $filled_w != "title"){ $w_title_count = "want" . "$want_no_values"; $filled_w = ($_POST["$w_title_count"]); $want_no_values++; } $want_no_values=$want_no_values-2; echo "number of want titles:" . $want_no_values . "<br />"; echo "cat: " . $cat . "<br />"; echo "title: " . $title . "<br />"; echo "message: " . $details . "<br />"; echo "want_no_values: " . $want_no_values . "<br />"; echo "offer_no_values: " . $offer_no_values . "<br />"; if ($cat && $title && ($want_no_values >= 1) && ($offer_no_values >= 1)) { ////////////////////////////////////////////////////// ////////////////////want construct//////////////////// ////////////////////////////////////////////////////// $x=1; while ($x <= $want_no_values){ $w_points = "want" . $x . "pts"; $w_desc = "want" . $x . "desc"; $w_image = "want" . $x . "img"; if ($w_image){ $w_img_name = $_FILES['want1img']['name']; $w_img_type = $_FILES['$w_image']['type']; $w_img_size = $_FILES['$w_image']['size']; $w_img_tmpname = $_FILES['$w_image']['tmp_name']; $w_img_ext = substr($w_img_name, strpos($w_img_name, '.')); echo "w name:" . $w_img_name . "<br />"; print_r ($_FILES['want1img']); } if ($w_img_name){ move_uploaded_file($w_img_tmpname, "images/listings/$username" . "-" . "$w_img_name" . "-" . "$w_img_size" . "$ext") or die(mysql_error()); $w_image = "$username" . "-" . "$w_img_name" . "-" . "$w_img_size" . "$ext"; } echo $w_points; $w_item_name = ($_POST["want$x"]); $w_item_pts = ($_POST["$w_points"]); $w_item_desc = ($_POST["$w_desc"]); $want_item = "<tr><td width='25'></td><th colspan='3'><b>" . $w_item_name . "</b> - " . $w_item_pts . "pts</th></tr> <tr><td width='25'></td><td width='25'></td><th colspan='2'>" . $w_item_desc . $w_image . "</th></tr>"; $want_items = $want_items . $want_item; $x++; } $want_desc = "<table> <tr><th colspan='3'><h3>What I want!</h3></th></tr>" . $want_items . "</table>"; ////////////////////////////////////////////////////// ////////////////////offer construct/////////////////// ////////////////////////////////////////////////////// $x=1; while ($x <= $offer_no_values){ $o_points = "offer" . $x . "pts"; $o_desc = "offer" . $x . "desc"; echo $w_points; $o_item_name = ($_POST["offer$x"]); $o_item_pts = ($_POST["$o_points"]); $o_item_desc = ($_POST["$o_desc"]); $offer_item = "<tr><td width='25'></td><th colspan='3'><b>" . $o_item_name . "</b> - " . $o_item_pts . "pts</th></tr> <tr><td width='25'></td><td width='25'></td><th colspan='2'>" . $o_item_desc . "</th></tr>"; $offer_items = $offer_items . $offer_item; $x++; } $offer_desc = "<table> <tr><th colspan='3'><h3>What I offer!</h3></th></tr>" . $offer_items . "</table>"; $desc=$want_desc . $offer_desc; echo $desc; } else { echo "Please supply all the fields!\n"; } } } } else echo "You must be logged in to see this page!"; ?> </td><td width="250"> <?php include("sidebar.inc"); ?> </td> </table> </body> </html> <?php include("footer.inc"); ?> I know it's very messy, I'll probably end up rewriting it but this is what I get after supplying the right fields and uploading an image for the want section: Code: [Select] Number of offer titles:1 number of want titles:1 cat: 1 title: This is the title message: None still testing it! want_no_values: 1 offer_no_values: 1 w img name: want1ptswant1pts The only bit that is of any use is the name section: Code: [Select] w img name: Nothing is recieved and the file is not uploaded!! I probably have missed something out but I am very new to php so please help!! Thanks Cameron The upload script I'm using performs successfully in Google, but not in IE or FF. Hello all - I'm fairly new to PHP and have been following some online tutorials to learn more, but hit a wall concerning a form that would allow a user to upload an image to his/her specified directory. Basically, I'd like the user to have to put in a password to upload. This "password" would actually just be the name of their directory on the server, so if a user put in "michael83" in as their password, the image would upload to "http://www.mysite.com/images/uploaded/michael83/". Here's my code so far: <form name="newad" method="post" enctype="multipart/form-data" action="upload.php" onSubmit="return validate_form ( );"> <table> <tr><td><input type="file" name="image"></td></tr> <tr><td> </td></tr> <tr><td>Password:</td></tr> <tr><td><input type="text" name="password"></td></tr> <tr><td> </td></tr> <tr><td><input name="Submit" type="submit" value="Upload"></td></tr> </table> </form> <?php define ("MAX_SIZE","1536"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if(isset($_POST['Submit'])) { $image=$_FILES['image']['name']; $dir=$_POST['username']; if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "pdf") && ($extension != "gif")) { echo '<h4>Sorry, your file is an unknown extension.</h4>'; $errors=1; } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo '<h4>Sorry, you have exceeded the size limit.</h4>'; echo '<p>If you need more help with this, please <a href="#">contact us</a> directly.</p>'; $errors=1; } $newname="images/uploaded/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<h4>Oops, looks like the upload was unsuccessfull.</h4>'; echo '<p>If you continue to have problems, please <a href="#">contact us</a>.</p>'; $errors=1; }}}} if(isset($_POST['Submit']) && !$errors) { echo "<h4>Your file was uploaded successfully!</h4><br><br>"; echo '<a href="http://www.mysite.com/' . $newname . '">http://www.mysite.com/' . $newname . '</a><br><br>'; } ?> Any help would be greatly appreciated. Many thanks in advance! EDIT Note: I would be the one setting the directories up, so if the user enters a "password" (directory) that doesn't exist, the form would return an error. |