PHP - Pdf Not Uploading
Hi guys
I am using the code below to upload files, image files seem to upload ok, but for some reason I cnt seem to upload pdf files.. any suggestions? Thank you <?php ini_set('file_uploads','on'); ini_set('upload_max_filesize','1000M'); ini_set('max_execution_time', 0); 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("invoices/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "invoices/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } ?> <form action="" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> Similar Tutorialscan anyone tell me why this code doesn't work if it tries to upload like more than 3 files?: Code: [Select] <?php include_once "secure/connect_to_mysql.php"; function genRandomString($length = 20) { $characters = '0123456789'; $string =''; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; } if ($_POST['submit']) { $name = $_POST['name']; $id = $_POST['id']; $image = $_POST['image']; $event = $_POST['event']; $template = 'template.php'; $picture = '$name.png'; $id = genRandomString(); //this could be the uploaded picture $target_path = "images/"; foreach ($_FILES["uploadedfile"]["name"] as $key => $value) { $uploadfile = $target_path . basename($_FILES[uploadedfile][name][$key]); //echo $uploadfile; if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$key], $uploadfile)) { echo $value . ' uploaded<br>'; } //we need just the filename - no extension $picture_name = pathinfo($picture, PATHINFO_FILENAME); $sql = "INSERT INTO pictures (name, id, image, event) VALUES('$name', '$id','images/$value','$event')"; $rs = mysql_query($sql) or die ("Problem with the query: $sql<br>" . mysql_error()); echo mysql_error(); } copy($template, "$event.php"); } ?> <form action="new.php" method="post" enctype="multipart/form-data"><input name="id" type="hidden" value=<?php echo $id; ?> /><br /> Event Name:<input name="event" type="text" /><input name="image" id="image" type="hidden" value="images/<?php echo $value; ?>" /><input type="hidden" name="MAX_FILE_SIZE" value="900000000000000000000000000000000000000000000000000000000000000000000000000" /> Choose a file to upload: <div id="dynamicInput"> <br>Pictu <input type="file" id="file" name="uploadedfile[]" onClick="addInput('dynamicInput');" > </div> <input type="button" value="Add another text input" onClick="addInput('dynamicInput');"> <br /><input name="submit" type="submit" value="submit" /></form> is it the code or something else? Hi Guys
I run a small roofing company and have been asked by many customers to be able to view / print / save Invoices & Estimates online rather than post etc. I host my own private site using IIS 7, with PHP and MySQL installed and setup properly, I also have a hosted domain from 1and1 What I would like is: Login Area (I can do this using the MySQL for the database) Once the user logs in, I want them to be directed to their "own" page with links to Their Own Invoices, Estimates and PIctures I would like an option somewhere for them to upload pictures into their own folder so if anything happens to their roof, they can simply log onto their account upload the pic of the damage and I can see it. and vice versa Can someone help me out a little? All I have so far is the Login page I am using xammp with FileZilla running on it. I've changed my php.ini settings to "C:/xxx/tmp" directory but am unable to upload a file. Th cod is running but it dos not seem to upload the temporary fil. Plase somebody help me. ALso my form in upload.html has <form action="upload_file.php" method="post" enctype="multipart/form-data"> Hi All, I am having trouble with this script that was from a example script online, basically I am getting the last error message everytime I try an up a zip file? Unknown Error: No file uploaded <?php include('dbconnect.php'); session_start(); $user_id = $_SESSION['user_id']; $query = " SELECT * FROM roms WHERE user_id = '$user_id' ORDER BY rom_date DESC LIMIT 1"; $result = mysql_query($query); if (!mysql_query($query)) { die('Error: ' . mysql_error()); } while($row = mysql_fetch_array($result)) { $_SESSION['rom_version'] = $row['rom_version']; } if ((!empty($_FILES["rom"])) && ($_FILES['rom']['error'] == 0)) { $filename = $user_id . $_SESSION['rom_version'] . '.zip'; $ext = substr($filename, strrpos($filename, '.') + 1); if (($ext == "zip") && ($_FILES["rom"]["type"] == "application/zip") && ($_FILES["rom"]["size"] < 2500000)) { $newname = dirname(__FILE__).'roms/'.$filename; if (!file_exists($newname)) { if ((move_uploaded_file($_FILES['uploaded_file'][ 'tmp_name'],$newname))) { echo "It's done! The file has been saved as: ".$newname; } else { echo "Error: A problem occurred during file upload!"; } } else { echo "Error: File ".$_FILES["rom"]["name"]." already exists"; } } else { echo "Error: Only .zip images under 250mb are accepted for upload"; } } else { echo "Unknown Error: No file uploaded"; } ?> 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. I have made a script to upload a few files from the pc to my server.. like i upload big files which are generally above 50mb of size.. but most of the times as there is some problem with the internet the hours of wait is just ruined.. is there a better way to upload files.. or anything that if the internet connection is interupted the downloading starts from wer it stopped cuz of the problem.. please help.. i use the normal function for uploading a file move_uploaded_file($_FILES['song1_upload']['tmp_name'] can anyone give a better idea than this? 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. i am using the fancy upload script for post attachments on my forum. the problem is that when a user starts a new post and adds an attachment the attachment is uploaded before the post is complete. so how would i associate the attachment with the post that they are going to post when i have no post id to go off? i had tried not uploading the files straight away and instead populate an input box with the filenames but i cant figure it out with this script. Anyone got any other options or ideas? Hi guys I have got this code here, giving quite a few errors and was wondering if anyone could help me sort it out, the script (should) run straight away just have to edit the database connect, I've tried manually creating the table and taking out the create table but when I try and upload an image I get these errors: Warning: move_uploaded_file(latest.img) [function.move-uploaded-file]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/php/image.php on line 23 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/Applications/XAMPP/xamppfiles/temp/php2lgspw' to 'latest.img' in /Applications/XAMPP/xamppfiles/htdocs/php/image.php on line 23 Warning: fopen(latest.img) [function.fopen]: failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/php/image.php on line 24 Warning: filesize() [function.filesize]: stat failed for latest.img in /Applications/XAMPP/xamppfiles/htdocs/php/image.php on line 25 Warning: fread() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/php/image.php on line 25 here is the code: Code: [Select] <?php // Connect to database $errmsg = ""; if (! @mysql_connect("localhost","root","")) { $errmsg = "Cannot connect to database"; } @mysql_select_db("test"); // First run ONLY - need to create table by uncommenting this // Or with silent @ we can let it fail every subsequent time ;-) $q = < < <CREATE create table pix ( pid int primary key not null auto_increment, title text, imgdata longblob) CREATE; @mysql_query($q); // Insert any new image into database if ($_REQUEST[completed] == 1) { // Need to add - check for large upload. Otherwise the code // will just duplicate old file ;-) // ALSO - note that latest.img must be public write and in a // live appliaction should be in another (safe!) directory. move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img"); $instr = fopen("latest.img","rb"); $image = addslashes(fread($instr,filesize("latest.img"))); if (strlen($image) < 149000) { mysql_query ("insert into pix (title, imgdata) values (\"". $_REQUEST[whatsit]. "\", \"". $image. "\")"); } else { $errmsg = "Too large!"; } } // Find out about latest image $gotten = @mysql_query("select * from pix order by pid desc limit 1"); if ($row = @mysql_fetch_assoc($gotten)) { $title = htmlspecialchars($row[title]); $bytes = $row[imgdata]; } else { $errmsg = "There is no image in the database yet"; $title = "no database image available"; // Put up a picture of our training centre $instr = fopen("../wellimg/ctco.jpg","rb"); $bytes = fread($instr,filesize("../wellimg/ctco.jpg")); } // If this is the image request, send out the image if ($_REQUEST[gim] == 1) { header("Content-type: image/jpeg"); print $bytes; exit (); } ?> <html><head> <title>Upload an image to a database</title> <body bgcolor=white><h2>Here's the latest picture</h2> <font color=red><?= $errmsg ?></font> <center><img src=?gim=1 width=144><br> <b><?= $title ?></center> <hr> <h2>Please upload a new picture and title</h2> <form enctype=multipart/form-data method=post> <input type=hidden name=MAX_FILE_SIZE value=150000> <input type=hidden name=completed value=1> Please choose an image to upload: <input type=file name=imagefile><br> Please enter the title of that pictu <input name=whatsit><br> then: <input type=submit></form><br> <hr> By Graham Ellis - graham@wellho.net </body> </html> Hello, I have written a PHP upload script.. all is well, so far... apart from the moving of the file at the very end of the script. Here's my script.. <? /* This script handles the uploading of a users photos to the display screen slideshows. 1. Collects data from uploaded image 2. Checks to see if database table exists for the screen in question. 2. Inserts record into database should a table exist. Otherwise, kill script. 3. Takes ID of inserted record from the database 4. Renames photo to the ID of the inserted record 5. Moves photo to the directory holding the images for the screen 6. Modifies entry inserted above to include new image location */ //Config include_once "../../includes/config/config.php"; //Retrieve the screen the user is uploading to $area = $_POST["area"]; //Check to see if screen exists $query = "SELECT * FROM screen_areas WHERE area='$area'"; $query = mysql_query($query); $num_rows = mysql_num_rows($query); if($num_rows=="0") { die("Photo upload could not be completed. Screen not found in database. (Error 3)"); } //Image Information $title = $_POST["title"]; $description = $_POST["description"]; //Simplify Image Data Array $image = $_FILES["image"]; $name = $image["name"]; //Photo Name $temp = $image["tmp_name"]; $extension = end(explode('.', $name)); //New Photo Location $new_location_directory = "/screens/images/$area"; $new_location = "$new_location_directory/$name"; //Check if new location (directory) exists $is_dir = is_dir($new_location_directory); if($is_dir=="FALSE") { die("Photo upload could not be completed. Screen directory could not be located. (Error 4)"); } //Insert record into database for this image $query = "INSERT INTO screen_data (area, title, description, location) VALUES ('$area', '$title', '$description', '$new_location')"; $query = mysql_query($query) or die(mysql_error()); //Get ID of inserted record $query = "SELECT * FROM screen_data WHERE title='$title' AND description='$description' AND location='$new_location'"; $query = mysql_query($query); while($row=mysql_fetch_array($query)) { $id = $row["id"]; } //Rename File $name_rename = "$id"; $name_rename .= "."; $name_rename .= "$extension"; //New Location after Renaming $new_location = "$new_location_directory/$name_rename"; //Move Photo if(move_uploaded_file("$temp", "$new_location")) { echo "The file ". basename($name). " has been uploaded"; } And here is the error returned to me: Quote Warning: move_uploaded_file(/screens/images/conference centre/23.png) [function.move-uploaded-file]: failed to open stream: No such file or directory in /Users/George/Desktop/Torindul/Customer Accounts/1035 The Gryphon School/Display CMS/Website/includes/functions/upload.php on line 69 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/Applications/MAMP/tmp/php/phpK8VJYe' to '/screens/images/conference centre/23.png' in /Users/George/Desktop/Torindul/Customer Accounts/1035 The Gryphon School/Display CMS/Website/includes/functions/upload.php on line 69 Any ideas as to why this may be occurring? Thanks in Advance, George. P.S I have CHMOD'd all directories to 755 where required. Ok I have finally got rid of my syntax errors with this upload script. Now im getting the error uploading your image. My folders are called project_files and project_thumbs. This is my script <?php $results = ""; error_reporting(E_ALL); ini_set("display_errors", 1); //Auto Thumbnail Function function create_thumbnail($source,$destination, $thumb_width) { $size = getimagesize($source); $width = $size[0]; $height = $size[1]; $x = 0; $y = 0; if($width> $height) { $x = ceil(($width - $height) / 2 ); $width = $height; } elseif($height> $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_image = imagecreatetruecolor($thumb_width,$thumb_width) or die('Cannot initialize new GD image stream'); $extension = get_image_extension($source); if($extension=='jpg' || $extension=='jpeg') $image = imagecreatefromjpeg($source); if($extension=='gif') $image = imagecreatefromgif($source); if($extension=='png') $image = imagecreatefrompng($source); imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width, $thumb_width,$width,$height); if($extension=='jpg' || $extension=='jpeg') imagejpeg($new_image,$destination); if($extension=='gif') imagegif($new_image,$destination); if($extension=='png') imagepng($new_image,$destination); } //Get Extension Function function get_image_extension($name) { $name = strtolower($name); $i = strrpos($name,"."); if (!$i) { return ""; } $l = strlen($name) - $i; $extension = substr($name,$i+1,$l); return $extension; } //Random Name Function function random_name($length) { $characters = "abcdefghijklmnopqrstuvwxyz01234567890"; $name = ""; for ($i = 0; $i < $length; $i++) { $name .= $characters[mt_rand(0, strlen($characters) - 1)]; } return "image-".$name; } $images_location = "/project_files/"; $thumbs_location = "/project_thumbs/"; $thumb_width = "100"; $maximum_size = "5000000"; //Check And Save Image if($_POST) { if($_FILES['image']['name'] == ""){ $results = "Please select the image you would like to upload by clicking browse"; } else{ $size=filesize($_FILES['image']['tmp_name']); $filename = stripslashes($_FILES['image']['name']); $extension = get_image_extension($filename); if($size > $maximum_size) { $results = "Your file size exceeds the maximum file size!"; } else if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $results = "Only the following extensions are allowed. 'jpg', 'jpeg', 'png', 'gif'."; } else { $image_random_name=random_name(15).".".$extension; $copy = @copy($_FILES['image']['tmp_name'], $images_location.$image_random_name); if (!$copy) { $results = "Error while uploadin your image! Please try again!"; } else{ create_thumbnail($images_location.$image_random_name,$thumbs_location.$image_random_name, $thumb_width); $results = "Your image has been uploaded!"; } } } } ?> and the form Code: [Select] <html> <head> <title>test</title> </head> <body> <?php echo $results; ?> <form action="#" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="5000000" /> <input type="file" name="image" /> <input type="submit" value="Upload Image" /> </form> </body> </html> I have made a script to upload a few files from the pc to my server.. like i upload big files which are generally above 50mb of size.. but most of the times as there is some problem with the internet the hours of wait is just ruined.. is there a better way to upload files.. i use the normal function move_uploaded_file($_FILES['song1_upload']['tmp_name'] can anyone give a better idea than this? 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 Hello everyone, I'm writing a script that allows a user to upload multiple attachments to an email from PHP. So far, everything seems to be working except the multiple attachments part. If I upload one file, it works. If I upload 2, it's messing up the file names so the files don't exist. So if I upload a.jpg, it works. If I upload a.jpg and b.jpg, b.jpg gets named a b.jpg. Can someone help me understand why this is happening and how to fix it? I'm almost certain its happening on my while loop around lune 72, but the more I look at the syntax the more it looks okay to me. I had it appending the path to the file names (so a.jpg become uploads/a.jpg) so I commented that out in hopes that was causing the error but it didn't fix it. Below is the full script. <?php /******************************************* /* contact_us_process.php /* Author: Brandon Pence (brandonpence@gmail.com) /* /* Desc: This page process and checks the submitted form. /* /* variable meaning /* -------- ------- /* $FieldCheck Instance of the FieldCheck class. /* /******************************************/ //start session session_start(); //include files require ("./inc/include.inc.php"); //include Field Check Class include("classes/FieldCheck.php"); //instantiate fieldcheck class $FieldCheck = new FieldCheck; extract($_POST); /*****DEBUG*********/ echo '<h1>POST ARRAY:</h1>'; print_r($_POST); echo '<hr/>'; echo '<h1>DATAFILE:</h1>'; print_r($datafile); echo 'foreach: <hr/>'; echo '<h1>FILES ARRAY:</h1>'; print_r($_FILES); echo '<hr/>'; echo 'File name test: '.$_FILES['uploadedfile']['name']['0'].'<br/>'; echo 'File name test: '.$_FILES['uploadedfile']['name']['1'].'<br/>'; echo 'File name test: '.$_FILES['uploadedfile']['name']['2'].'<br/>'; /********************/ //foreach($datafile as $key=>$value){ //echo 'Datafile: '.$datafile.' || Key: '.$key.' || Value: '.$value.'<br/>'; //$value = $id.'/'.$value; //echo 'Datafile: '.$datafile.' || Key: '.$key.' || Value: '.$value.'<br/>'; //} if(file_exists("uploads/$id")){ echo 'Folder Exists!'; }else{ echo 'Folder does not exist. Create folder.'; //create directory mkdir("uploads/$id",0777,true); } //path we want the files stored in $target_path = "uploads/$id/"; //begin counter $i = 0; $files = array(); //begin loop while($i < 3){ //make sure each array key has valid data if(!is_null($_FILES['uploadedfile']['name'][$i])){ //append path to filenames in array //$target_path = $target_path . basename($_FILES['uploadedfile']['name'][$i]); //upload files if(move_uploaded_file($_FILES['uploadedfile']['name'][$i], $target_path)) { echo "The file ". basename($_FILES['uploadedfile']['name'][$i]). " has been uploaded"; $files[$i] = 'uploads/'.$id.'/'.$_FILES['uploadedfile']['name'][$i]; } //if file upload failed }else{ echo "There was an error uploading the file, please try again!"; } $i++; } //validate input if (!$FieldCheck->checkName($your_name)){ $errors['your_name'] = "Your name is not valid.";} if (!$FieldCheck->isEmpty($your_date)){ $errors['your_date'] = "Your date is not valid.";} if (!$FieldCheck->isEmpty($your_message)){ $errors['your_message'] = "Your message is not valid.";} foreach($_POST as $key=>$value){ $fields[$key] = $value; } //print_r($_POST); //check for error messages if (isset($errors)) { $_SESSION['errors'] = $errors; $_SESSION['fields'] = $fields; $_SESSION['error_msg'] = "Errors found! Please review your entries."; $url = "./testimonials.php?action=errors"; header ("Location: $url"); exit; }else{ echo '$files ARRAY:'; print_r($files); // email fields: to, from, subject, and so on $to = "a@c.om"; $from = "a@b.com"; $subject ="Testing Script"; $message = "My message"; $headers = "From: $from"; // boundary $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // headers for attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // multipart boundary $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; $message .= "--{$mime_boundary}\n"; // preparing attachments for($x=0;$x<count($files);$x++){ $file = fopen($files[$x],"rb"); $data = fread($file,filesize($files[$x])); fclose($file); $data = chunk_split(base64_encode($data)); $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; $message .= "--{$mime_boundary}\n"; } // send $ok = @mail($to, $subject, $message, $headers); if ($ok) { echo "<p>mail sent to $to!</p>"; } else { echo "<p>mail could not be sent!</p>"; } echo 'EMAIL SENT!'; } ?> Hi everybody i have two problems with my code first one i cant upload .png files to the img folder (no problem with the other extensions ) the other one "if file exist" part doesnt work i dont get the message "File alredy exist" after uploading second time Can you help plase <form action="upload.php" method="post" enctype="multipart/form-data"> <input name="dosya" type="file"> <input name="submit" type="submit" value="Gonder"> </form> <?php $kaynak=$_FILES["dosya"]["tmp_name"]; $ad=$_FILES["dosya"]["name"]; $tur=$_FILES["dosya"]["type"]; $boyut=$_FILES["dosya"]["size"]; $hedef="./img"; if($tur == "image/jpeg" || $tur == "image/png" || $tur == "image/pjpeg" ) { if(!file_exists($ad)) { move_uploaded_file($kaynak,$hedef.'/'.$ad); echo "ok"; } else echo "File already exist"; } ?> 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> hi, i'm trying to create simple form that will also upload only xml data. first, the user will need to upload an xml document only by clicking submit, the data will be posted to the server and the user will be redirected to uploader.php. This PHP file is going to process the form data and do all the work. #upload.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <body> <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="500" /> Please select the correct file that you require to create an XML export. <br/> <label for="uploadfile">Filename:</label> <input name="uploadfile" type="file" size="100"/> <input type="submit" value="Upload File" /> </form> </body> </html> second, i'd like to process the data and post the information to another php document that will parse the xml document. this particular file is not getting past the first if statement. i'm not really seeing why??? #uploader.php <?php //File upload restrictions parameters //Will only restrict to allowing xml documents to be uploaded if ((($_FILES["file"]["type"] == "application /xml") { 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 />"; //Save the uploaded files to a directory //If the file already exists with the same date stamp, do not upload if (file_exists("../upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } //If the file does not exist, create a new entry else { move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "../upload/" . $_FILES["file"]["name"]; } } } //Create an error messag else { echo "This is an invalid file. Please make sure an XML document has been selected to upload. Thanks."; } // make an error handler which will be used if the upload fails function error($error, $location, $seconds = 20) { header("Refresh: $seconds; URL=\"$location\""); echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n". '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n". '<html lang="en">'."\n". ' <head>'."\n". ' <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n". ' <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n". ' <title>Upload error</title>'."\n\n". ' </head>'."\n\n". ' <body>'."\n\n". ' <div id="Upload">'."\n\n". ' <h1>Upload failure</h1>'."\n\n". ' <p>An error has occured: '."\n\n". ' <span class="red">' . $error . '...</span>'."\n\n". ' The upload form is reloading</p>'."\n\n". ' </div>'."\n\n". '</html>'; exit; } // end error handler ?> third, once the simple file parses the information.. i'd like to display a dropdown menu that will allow a person to select what entry they'd like to be displayed, namely page to be redirected to. #dropdown.php <?php $drop = $_REQUEST['dropdown']; ?> <html> <body> <form action="results.php" method="POST" name="links"> <select name="dropdown" value="options"> <option value"form.php">Select a Format</option> <option value="1.php">1</option> <option value="2.php">2</option> <option value="3.php">3</option> <option value="4.php">4</option> <option value="5.php">5</option> </select> <br/> <br/> <input type="submit" value="Submit Query"/> </body> </html> fourth part I, based on the above information... the user should have a page with a include("livesearch.php") for 1.php, but i will place livesearch.php code below... #livesearch.php $target_path = $target_path . basename($_FILES['uploadedfile']['tmp_name']); $xmlDoc=new DOMDocument(); $xmlDoc->load("uploader.ph"); $x=$xmlDoc->getElementsByTagName('link'); //get the q parameter from URL $q=$_GET["q"]; //lookup all links from the xml file if length of q>0 if (strlen($q)>0) { $hint=""; for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('PPC'); $z=$x->item($i)->getElementsByTagName('url'); if ($y->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) { if ($hint=="") { $hint="<a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } else { $hint=$hint . "<br /><a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } } } } } // Set output to "no suggestion" if no hint were found // or to the correct values if ($hint=="") { $response="no suggestion"; } else { $response=$hint; } //output the response echo $response; ?> fourth part II, the above code will be part of 1.php... this part of the form will ideally return a livesearch query from the uploaded xml document for the checked boxes by an element's name. #form.php <html> <head> <script type="text/javascript"> function showResult(str) { if (str.length==0) { document.getElementById("livesearch").innerHTML=""; document.getElementById("livesearch").style.border="0px"; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("livesearch").innerHTML=xmlhttp.responseText; document.getElementById("livesearch").style.border="1px solid #A5ACB2"; } } xmlhttp.open("GET","livesearch.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <?php echo "<form> Please place element1 # to search: <input type='text' size='30' onkeyup='showResult(this.value)' /> <div id='livesearch'></div> </form>"; // This is to collect box array value as global_variables is set off in PHP5 by default // // variable that will send $box information from the checkboxes named getXMLbox to // an variable array $box=$_POST['getXMLbox']; if(empty($box)) { echo("These are the boxes that WERE not selected: $box"); } else { $N = count($box); echo("These are the boxes that ARE selected: $N "); for($i=0; $i<$N; $i++) { echo($box[$i] . " "); } } while (list ($key,$val) = @each ($box)) { echo "$val,"; } echo "<form method=post action='simple.php'>"; echo "<table border='0' cellspacing='0' style='border-collapse: collapse' width='100' > <tr bgcolor='#ffffff'> <td width='25%'><input type=checkbox name=getXMLbox[] value='element1'></td> <td width='25%'> element1</td> </tr> <tr bgcolor='#ffffff'> <td width='25%'><input type=checkbox name=getXMLbox[] value='element2'></td> <td width='25%'> element2</td> </tr> <tr> <td><br/></td> </tr> <tr> <td colspan =6 align=center><input type=submit name=SubmitForm value='Submit Query'></form></td> </tr> </table>"; ?> finally, i'd like to parse the data with a php5 function and display the xml information onto the screeen or have a dialog box open up for a person to save as. #simple.php <?php /* we will use simpleXML to transfer xml data to parse and read xml data */ //load the xml file to $file $file = ($_FILES["file"]["name"]); #load xml data $xml = simplexml_load_file($file) or die ("The connection to could not load the XML document. Please try again. \n"); #display the entire document echo ('$xml'); ?> so basically, i'm a bit lost and not getting the right outcome that i'd like. can someone please assist? many thanks. Hi, I have a system that uses PHP to create a Word Doc as information is extracted from a table using this code: Code: [Select] header("Content-type: applicaton/save"); header("Content-Disposition: attachment; filename="FILE NAME".doc"); header("Pragma: no-cache"); header("Expires: 0"); This part of the system I'm trying to implement is working fine. However, what I would ideally like for it to do (and at this point I understand that it sounds a bit pointless) is to save that downloaded file onto a specified folder location on the server directory i.e. to the uploads folder. This will enable all users of the system to then download / view these files as required. I'm not sure whether this is possible or not but and help would be greatly appreciated. Thanks in advance, Ben Hello
I want to know to upload the XML file to mysql using php as i am new to xml any help appreciated.
awaiting your valuable reply
here also i am attaching the xml file which i want to upload
Thanks in Advance
Attached Files
xml1.xml 4.89KB
2 downloads |