PHP - Upload Image And Data Error
Similar TutorialsOk so I have a form to submits to a .php file that creates an image. This works fine, but I also want the info from the form to be sent to MySQL database. The problem is that something in a script I "required" called core.inc.php is interfering and so no image is output. Here is core.inc.php: Code: [Select] <?php ob_start(); session_start(); $current_file = $_SERVER['SCRIPT_NAME']; if(isset($_SERVER['HTTP_REFERER'])&&!empty($_SERVER['HTTP_REFERER'])) { $http_referer = $_SERVER['HTTP_REFERER']; } function loggedin() { if(isset($_SESSION['user_id'])&&!empty($_SESSION['user_id'])) { return true; } else { return false; } } function getuserfield($field) { $query="SELECT `$field` FROM `Users` WHERE `id`='".$_SESSION['user_id']."'"; if($query_run=mysql_query($query)) { if($query_result = mysql_result($query_run, 0, $field)) { return $query_result; } } } ?> Here is the code for the image creating .php file: Code: [Select] <?php require 'connect.inc.php'; require 'core.inc.php'; $title = $_REQUEST['title'] ; $user_id = getuserfield('id'); $query = "INSERT INTO `---` VALUES ('".mysql_real_escape_string($title)."','".mysql_real_escape_string($user_id)."')"; $query_run = mysql_query($query); //There is some more code in here obviously, but it's irrelevant header('Content-type: image/png'); imagepng($image_f); imagedestroy($image_f) Can anybody give me some idea of what is conflicting or what I can do to fix it? so what i have going on is that i need help writing a basic script to upload original and copy with resize for thumbnail. then also need to rename both image files with content in the form. My server supports GD Library and that imagemagik or whatever it is lol. upload dirs orig: ../media/photos/ thumb: ../media/photos/thumb/ mySQL DB: name: m_photos fields: id(INT) m_cat(varchar) m_sub_cat(varchar) pic(varchar) description(varchar) p_group(varchar) I have the form written up for how it should look like: Code: [Select] <form action="upload.php" method="post" enctype="multipart/form-data"> Upload an image for processing<br /> <input type="file" name="Image"><br /> <select name="sub_group"> <option value="Photo Shoot">Photo Shoot</option> <option value="Live Performances">Live Performances</option> <option value="Randoms">Randoms</option> <option value="Fan Photos">Fan Photos</option> </select><br /> Location: <input type="text" name="p_group" /><br /> Date of Pic: <input type="text" name="date" /><br /> Description: <input type="text" name="description" /><br /> <input type="submit" value="Upload"> </form> so what needs to happen is for the file upload name. it needs to grab a count from "p_group" database to give it a starting number in a "00" pattern and then the date of pic needs to go in there next then the p_group name. so when the files gets uploaded it would look something like this after upload. "03 - Oct 21, 2011 - The Mex.jpg" NOTE: all pics must be converted to ".jpg" extension. both the orig and thumb will use that same file name cuz they just go into different dirs re-sizing for the thumbnail should be done by aspect ratio and needs to either be 300px width or 400px height. so if anyone would like to help me out please do. im not the greatest at writing in php yet Hi I have an upload script which uploads an image then resizes The error Code: [Select] Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 7776 bytes) in Dir/UploadScript.php on line 234 The code function $strNewFileName = date("YmdHis").rand(0,5000).".".$this->strFileExt; $this->strNewFileName = $strNewFileName; $strDir = $_SERVER['DOCUMENT_ROOT'].$this->strSaveDir.$strNewFileName; $strTNDir = $_SERVER['DOCUMENT_ROOT'].$this->strSaveDir."tn_".$strNewFileName; move_uploaded_file($this->arrUploadFile['tmp_name'], $strDir); $image_p = imagecreatetruecolor($this->intNewWidth, $this->intNewHeight); switch($this->strFileExt){ case "jpg": $image = imagecreatefromjpeg($strDir); break; case "gif": $image = imagecreatefromgif($strDir); break; case "png": $image = imagecreatefrompng($strDir); break; } imagecopyresampled($image_p, $image, 0, 0, 0, 0, $this->intNewWidth, $this->intNewHeight, $this->intCurWidth, $this->intCurHeight); $blnSuccessUpload = false; switch($this->strFileExt){ case "jpg": if(imagejpeg($image_p, $strTNDir)){ $blnSuccessUpload = true; } break; case "gif": if(imagegif($image_p, $strTNDir)){ $blnSuccessUpload = true; } break; case "png": if(imagepng($image_p, $strTNDir)){ $blnSuccessUpload = true; } } imagedestroy($image_p); return $blnSuccessUpload; the Line causing issues (234) is Code: [Select] $image = imagecreatefromjpeg($strDir); Now that image is created but the TN is not //Edit Just a note. I have ini_set('memory_limit', 16MB); if you notice the allocated memory is less than the memory allowed. The Script:
<?php if (isset($_POST['submit'])) { $j = 0; //Variable for indexing uploaded image $target_path = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/uploads/"; //Declaring Path for uploaded images for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) $file_extension = end($ext); //store extensions in the variable $new_image_name = md5(uniqid()) . "." . $ext[count($ext) - 1]; $target_path = $target_path . $new_image_name;//set the target path with a new name of image $j = $j + 1;//increment the number of uploaded images according to the files in array if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded. && in_array($file_extension, $validextensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>'; for ($i = 0; $i < count($_FILES['file']['name']); $i++) { $tqs = "INSERT INTO images (`original_image_name`, `image_file`, `date_created`) VALUES ('" . $_FILES['file']['name'][$i] . "', '" . $new_image_name . "', now())"; $tqr = mysqli_query($dbc, $tqs); } // To create the thumbnails. function make_thumb($src, $dest, $desired_width) { /* read the source image */ $source_image = imagecreatefromjpeg($src); $width = imagesx($source_image); $height = imagesy($source_image); /* find the "desired height" of this thumbnail, relative to the desired width */ $desired_height = floor($height * ($desired_width / $width)); /* create a new, "virtual" image */ $virtual_image = imagecreatetruecolor($desired_width, $desired_height); /* copy source image at a resized size */ imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height); /* create the physical thumbnail image to its destination */ imagejpeg($virtual_image, $dest); } $src = $target_path; $dest = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/thumbs/"; $desired_width = 100; make_thumb($src, $dest, $desired_width); } else {//if file was not moved. echo $j. ').<span id="error">please try again!.</span><br/><br/>'; } } else {//if file size and file type was incorrect. echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>'; } } } ?>With this: $dest = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/thumbs/";I get this error message: Warning: imagejpeg(C:/xampp/htdocs/gallerysite/multiple_image_upload/thumbs/): failed to open stream: No such file or directory in C:\xampp\htdocs\gallerysite\multiple_image_upload\upload.php on line 49With this: $dest = "http://localhost/gallerysite/multiple_image_upload/thumbs/";I get this error message: Warning: imagejpeg(http://localhost/gallerysite/multiple_image_upload/thumbs/): failed to open stream: HTTP wrapper does not support writeable connections in C:\xampp\htdocs\gallerysite\multiple_image_upload\upload.php on line 49When I try deleting the "thumbs" folder and then try to upload an image, then I get this error message: Warning: imagejpeg(C:/xampp/htdocs/gallerysite/multiple_image_upload/thumbs/): failed to open stream: Invalid argument in C:\xampp\htdocs\gallerysite\multiple_image_upload\upload.php on line 49The spot of line 49 is this, at the spot where the script creates the thumbnails: /* create the physical thumbnail image to its destination */ imagejpeg($virtual_image, $dest); }Also, with this part right here I am not getting an error message, which means that this part works fine in comparison: $target_path = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/uploads/"; //Declaring Path for uploaded imagesThe script itself works fine. The script also uses javascript for multiple image upload. I am using XAMPP. The folder "thumbs" is set to "read-only", when I try to uncheck the "read-only" option in the properties in Windows then it sets itself back again to "read-only". Then again, the script works fine when it comes to the "uploads" folder. This is mentioned in comparison to the "thumbs" folder. Any suggestions on how to solve this? EDIT: I am using XAMPP. The folder "thumbs" is set to "read-only", when I try to uncheck the "read-only" option in the properties in Windows then it sets itself back again to "read-only". I am wondering if I would have issue that the option sets itself back again with Linux? Edited by glassfish, 11 October 2014 - 05:35 PM. files that upload during insert/submit form was gone , only files upload during the update remain , is the way query for update multiple files is wrong ? $targetDir1= "folder/pda-semakan/ic/"; if(isset($_FILES['ic'])){ $fileName1 = $_FILES['ic']['name']; $targetFilePath1 = $targetDir1 . $fileName1; //$main_tmp2 = $_FILES['ic']['tmp_name']; $move2 =move_uploaded_file($_FILES["ic"]["tmp_name"], $targetFilePath1); } $targetDir2= "folder/pda-semakan/sijil_lahir/"; if(isset($_FILES['sijilkelahiran'])){ $fileName2 = $_FILES['sijilkelahiran']['name']; $targetFilePath2 = $targetDir2 . $fileName2; $move3 =move_uploaded_file($_FILES["sijilkelahiran"]["tmp_name"], $targetFilePath2); } $targetDir3= "folder/pda-semakan/sijil_spm/"; if(isset($_FILES['sijilspm'])){ $fileName3 = $_FILES['sijilspm']['name']; $targetFilePath3 = $targetDir3 . $fileName3; $move4 =move_uploaded_file($_FILES["sijilspm"]["tmp_name"], $targetFilePath3); } $query1=("UPDATE semakan_dokumen set student_id='$noMatrik', email= '$stdEmail', surat_tawaran='$fileName', ic='$fileName1',sijil_lahir='$fileName2',sijil_spm= '$fileName3' where email= '$stdEmail'");
How can i edit just one image at on time with a multiple image upload form? I have the images being stored in a folder and the path being stored in MySQL. I also have the files being uploaded with a unique id. My issue is that I want to be able to pass the values of what is already in $name2 $name3 $name4 if I only want to edit $name1. I don't want to have to manually update the 4 images. Here is the PHP: Code: [Select] <?php require_once('storescripts/connect.php'); mysql_select_db($database_phpimage,$phpimage); $uploadDir = 'upload/'; if(isset($_POST['upload'])) { foreach ($_FILES as $file) { $fileName = $file['name']; $tmpName = $file['tmp_name']; $fileSize = $file['size']; $fileType = $file['type']; if ($fileName != ""){ $filePath = $uploadDir; $fileName = str_replace(" ", "_", $fileName); //Split the name into the base name and extension $pathInfo = pathinfo($fileName); $fileName_base = $pathInfo['fileName']; $fileName_ext = $pathInfo['extension']; //now we re-assemble the file name, sticking the output of uniqid into it //and keep doing this in a loop until we generate a name that //does not already exist (most likely we will get that first try) do { $fileName = $fileName_base . uniqid() . '.' . $fileName_ext; } while (file_exists($filePath.$fileName)); $file_names [] = $fileName; $result = move_uploaded_file($tmpName, $filePath.$fileName); } if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $fileinsert[] = $filePath; } } $mid = mysql_real_escape_string(trim($_POST['mid'])); $cat = mysql_real_escape_string(trim($_POST['cat'])); $item = mysql_real_escape_string(trim($_POST['item'])); $price = mysql_real_escape_string(trim($_POST['price'])); $about = mysql_real_escape_string(trim($_POST['about'])); $fields = array(); $values = array(); $updateVals = array(); for($i = 0; $i < 4; $i++) { $values[$i] = isset($file_names[$i]) ? mysql_real_escape_string($file_names[$i]) : ''; if($values[$i] != '') { $updateVals[] = 'name' . ($i + 1) . " = '{$values[$i]}'"; } } $updateNames = ''; if(count($updateVals)) { $updateNames = ", " . implode(', ', $updateVals); } $update = "INSERT INTO image (mid, cid, item, price, about, name1, name2, name3, name4) VALUES ('$mid', '$cat', '$item', '$price', '$about', '$values[0]', '$values[1]', '$values[2]', '$values[3]') ON DUPLICATE KEY UPDATE cid = '$cat', item = '$item', price = '$price', about = '$about' $updateNames"; $result = mysql_query($update) or die (mysql_error()); Hello I am having problems uploading an image through a HTML form. I want the image to be uploaded to the server and the image name to be written to the mysql database. Below is the code I am using: Code: [Select] <?php if (isset($_POST['add'])){ echo "<br /> add value is true"; $name = $_POST['name']; $description = $_POST['description']; $price = $_POST['price']; $category_id = $_POST['category_name']; $image = $_FILES['image']['name']; //file path of the image upload $filepath = "../images/"; //mew name for the image upload $newimagename = $name; //new width for the image $newwidth = 100; //new height for the image $newheight = 100; include('../includes/image-upload.php'); mysql_query("INSERT INTO item (item_name, item_description, item_price, item_image) VALUES ('$name','$description','$price','$image')"); ?> Here is the image-upload.php file code: Code: [Select] <?php //assigns the file to the image $image =$_FILES["image"]["name"]; $uploadedfile =$_FILES["image"]["tmp_name"]; if ($image) { //retrieves the extension type from image upload $extension = getextension($image); //converts extension to lowercase $extension = strtolower($extension); //create image from uploaded file type if($extension=="jpg" || $extension=="jpeg") { $uploadedfile = $_FILES['image']['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); }else if($extension=="png") { $uploadedfile = $_FILES['image']['tmp_name']; $src = imagecreatefrompng($uploadedfile); }else{ $src = imagecreatefromgif($uploadedfile); } //creates a list of the width and height of the image list($width,$height)=getimagesize($uploadedfile); //adds color to the image $tmp = imagecreatetruecolor($newwidth,$newheight); //create image imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); //set file name $filename = $filepath.$newimagename.".".$extension; $imagename = $newimagename.".".$extension; //uploads new file with name to the chosen directory imagejpeg($tmp,$filename,100); //empty variables imagedestroy($src); imagedestroy($tmp); } ?> Any help would be appreciated, fairly new to all this! Thanks!!! Why does it give me the "There was an error uploading the file, please try again!" error message? I've checked through the code, and I've looked to see what is wrong. I'm thinking it MIGHT be because of: $target_path = $target_path . $output; if(pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION)=="zip") { if(move_uploaded_file($output, $target_path)) { But, heres the full code: <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php if(!$_SESSION['user']) { echo "Your not allowed to upload plugins! <a href='index.php'>Go Home</a> or <a href='register.php'>Make an account</a>."; } else { echo "<a href='start_upload.php'>Upload</a> | <a href='search.php'>Search & Browse</a> | <a href='/news'>News & Announcements</a> | <a href='logout.php'>Logout</a><hr>"; $description = $_POST['description']; $description = mysql_real_escape_string($description); $ip = $_SERVER['REMOTE_ADDR']; $date = date('m-d-y'); $title = $_POST['title']; $title = mysql_real_escape_string($title); $user = $_SESSION['SESSION']; $target_path = "mods/"; $query = mysql_query("SELECT COUNT(id) FROM mods"); $finish_query = mysql_fetch_assoc($query); $output = $finish_query['COUNT(id)'] + 1; $target_path = $target_path . $output; if(pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION)=="zip") { if(move_uploaded_file($output, $target_path)) { echo "The mod ". basename($_FILES['file']['name']) . " has been uploaded. Check it out <a href='mods/". $output ."'>HERE.</a>"; mysql_query("INSERT INTO mods VALUES('', '$ip', '$date', '$title', '$description', '$user')"); } else{ echo "There was an error uploading the file, please try again!"; } } else { echo "You cannot use a .". pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION) ." extension! .zip is currently the only file extension allowed."; } } include("includes/footer.php"); ?> i have this in my php.ini Quote ;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;; ; Whether to allow HTTP file uploads. ; http://php.net/file-uploads file_uploads = On ; Temporary directory for HTTP uploaded files (will use system default if not ; specified). ; http://php.net/upload-tmp-dir upload_tmp_dir = "c:/wamp/tmp" ; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 32M but when i upload i get error # 1 which is The uploaded file exceeds the upload_max_filesize directive in php.ini what am i doing wrong? <body> <form enctype="multipart/form-data" action="uploadfile.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="10485760" /> Choose a file to upload: <input name="file" type="file" /><br /> <input type="submit" value="Upload File" /> </form> </body> <?php include 'db_fns.php'; function RemoveExtension($strName) { $ext = strrchr($strName, '.'); if($ext !== false) { $strName = substr($strName, 0, -strlen($ext)); } return $strName; } $name = $_FILES["file"]['name']; $type = $_FILES["file"]['type']; $error = $_FILES["file"]['error']; $size = $_FILES["file"]['size']; $tmp = $_FILES["file"]["tmp_name"]; $date = date("Y-m-d"); echo $_FILES["file"]['error']; if($type == 'audio/mpeg' || $type == ' audio/mp3'){ $song_name = RemoveExtension($name); $query = "INSERT into uploads(song_name, created_at) VALUES ('$song_name', '$date')"; $result = mysqli_query($link, $query); $id = mysqli_insert_id($link); move_uploaded_file($tmp, "uploads/" . $id . ".mp3"); echo "your link is <a href='play.php?id=$id'> here</a>"; }else{ echo 'File must be in mp3 format'; } ?> This is my first time ever working with this type of stuff with PHP. So, I basically got this code from a tutorial at Tizag on how to upload files to your webiste. But everytime I do, I get an error message. I don't get a PHP error, I just get it from the code. "There was an error uploading the file, please try again!" <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php if(!$_SESSION['user']) { echo "Your not allowed to upload plugins! <a href='index.php'>Go Home</a> or <a href='register.php'>Make an account</a>."; } else { $description = $_POST['description']; $description = mysql_real_escape_string($description); $ip = $_SERVER['REMOTE_ADDR']; $date = date('m-d-y'); $title = $_POST['title']; $title = mysql_real_escape_string($title); $query = mysql_query("SELECT COUNT(id) FROM mods"); $finish_query = mysql_fetch_assoc($query); $output = $finish_query['COUNT(id)'] + 1; echo $output; $_FILES['uploadedfile']['name'] = $output; echo $_FILES['uploadfile']['name']; $target_path = "mods/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The mod ". basename( $_FILES['uploadedfile']['name']). " has been uploaded. Check it out HERE."; mysql_query("INSERT INTO mods VALUES('', '$ip', '$date', '$title', '$description', '$user')"); } else{ echo "There was an error uploading the file, please try again!"; } } include("includes/footer.php"); ?> After searching postings on multiple forums, I am officially now "Freaking OUT" trying to understand something that is probably very simple, but cannot seem to grasp. I simply want to read basic .csv data that is sent/uploaded directly to a PHP page, and to then append each record that shows up to a single .csv file on the server. The incoming data is supposed incoming via $_POST['csv'] ... at least that's what I was told. Each.csv record line being sent/uploaded is very simple (either single or multiple records in one small file): text1,text2,text3,text4,text5 For additional processing I know about 'explode', etc., but right now I am stuck even trying to do an 'echo' to display the simple incoming data "as is". One option I tried was: $postdata = file_get_contents("php://input"); echo $postdata; In the Java App monitoring I get the following after 3 records are sent/uploaded to the PHP URL: Server response status line: HTTP/1.1 200 OK I find this strange since I did not include... http_response_code(200); ... in the page code. Obviously, I do NOT know what I am doing here {SIGH}. Any assistance or guidance is appreciated. Thank you ! - FreakingOUT
Can anyone help me to fix this two error?
#upload directory path mysqli_select_db($conn, "test2") or die(mysql_error()); Thank you !
Hello, i'm trying to upload a file through a page, on a local wamp server. Here's the code i'm using: Code: [Select] <form action="upload_file.php" 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="Upload" /> </form>This is the form i'm using to pass my file Code: [Select] <?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_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 "Stored in: " . $_FILES["file"]["tmp_name"] . "<br />"; if (move_uploaded_file($_FILES["file"]["tmp_name"], $_SERVER['DOCUMENT_ROOT']. "/template_example/slideshow/images/" . $_FILES["file"]["name"])) { echo "Stored in: " . $_SERVER['DOCUMENT_ROOT'] . "localhost/template_example/slideshow/images/" . $_FILES["file"]["name"]; } } ?> The problem comes up if i try to upload an image file of size 1,07 MB. upload_max_filesize on my php.ini is at 2M. I also tried changing it to 2000M just to see if thats the problem. The error code i'm getting is 2 which means: Value: "2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form." from what i got on the internet. My operating system is windows XP SP2 and i have wamp server installed. Please help! hi, i am trying to code a file uploader in php using IIS server this is the code of the form: <html><body> <form method="post" enctype="multipart/form-data" action="processform.php"> <input type="hidden" name="MAX_FILE_SIZE" value="200000"> <input type="file" name="thefile"><br/> <input type="submit" value="Submit File...."> </form> </body></html> this is the code of processform.php <?php $upload_dir = "C:/Inetpub/wwwroot/cbt/upload/"; $upload_file = $upload_dir . basename($_FILES['thefile']['name']); if(copy($_FILE['thefile']['tmp_name'],$upload_file)){ echo "File copy was Successful!"; } else { echo "Oops... something went wrong..."; print_r($_FILES); } ?> now the problem is each time i try to click on the submit button after browsing any file it shows the message : Oops... something went wrong...Array ( [thefile] => Array ( [name] => 1.jpeg [type] => image/jpeg [tmp_name] => C:\temps\php13.tmp [error] => 0 [size] => 59592 ) ) help me guys...... wats the problem with the code ? Hi want to upload file using form's input type="file" then i want to display it on another page, As i am new to PHP i am doing this step by step so that I can test each step and go ahead. My first step is to upload file and check if its uploading in temp location.. I got same code from net.. I am using notepad++ thats why not sure abt syntax error, What I did is: <html> <body> <form action="index.php" method="POST" enctype="multipart/form-data"> Image: <input type="file" name="image"> <input type="submit" value="Upload"> </form> <?php mysql_connection("localhost","root","admin") or die(mysql_error()); mysql_select_db("searchdeals") or die(mysql_error()); echo $file = $_FILES['image']['tmp_name']; ?> </body> </html> Hi all, I'm using some code that I got from the net (I forget where but all credit to the author). I've tried to adapt it to suit my own needs (almost suceeded?). I have an upload page with 5 file uploads which is processed by this script: (I've annotated where I think the problems may be) UPLOAD FORM <table width="600" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#993399"> <tr> <form action="../uploads/upload2.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#993399"> <tr> <td><div align="center"><strong><h3>Upload your files</h3></strong></div></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center"><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </td> </form> </tr> </table> Here is "uploads.php" <?php $path1= "../uploads/".$HTTP_POST_FILES['ufile']['name'][0]; $path2= "../uploads/".$HTTP_POST_FILES['ufile']['name'][1]; $path3= "../uploads/".$HTTP_POST_FILES['ufile']['name'][2]; $path4= "../uploads/".$HTTP_POST_FILES['ufile']['name'][3]; $path5= "../uploads/".$HTTP_POST_FILES['ufile']['name'][4]; copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1); copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2); copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3); copy($HTTP_POST_FILES['ufile']['tmp_name'][3], $path4); copy($HTTP_POST_FILES['ufile']['tmp_name'][4], $path5); include '../includes/smile.php'; echo "<table width=\"900\"height=\"180\"cellpadding=\"5\" cellspacing=\"5\" background=\"../images/upbg.png\" align=\"center\"> <tr><td align=center><img src=\"$path1\" width=\"100\" height=\"100\"></td>"; echo "<td align=center><img src=\"$path2\" width=\"100\" height=\"100\"></td>"; echo "<td align=center><img src=\"$path3\" width=\"100\" height=\"100\"></td>"; echo "<td align=center><img src=\"$path4\" width=\"100\" height=\"100\"></td>"; echo "<td align=center><img src=\"$path5\" width=\"100\" height=\"100\"></td></tr></table>"; $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; $filesize2=$HTTP_POST_FILES['ufile']['size'][1]; $filesize3=$HTTP_POST_FILES['ufile']['size'][2]; $filesize4=$HTTP_POST_FILES['ufile']['size'][3]; $filesize5=$HTTP_POST_FILES['ufile']['size'][4]; if($filesize1 && $filesize2 && $filesize3 && $filesize4 && $filesize5 !=0) // possible error? { echo "<h3 align=center><img src=\"../images/niceone.png\"></h3>"; include '../includes/smilefoot.php'; } else { echo "<meta http-equiv='Refresh' content='0; url=../includes/fail.php'>"; // possible error? } ?> It took me an entire day to get it at this level of functionality where if you sucessfully upload your files you get a success message on the same page but otherwise are redirected to a failure page. The problem is, if you don't upload a file for each of the 5 form inputs, you get the succes message and then redirected to the fail page. Someone who actually knows something about php will probably see a solution straight away but I don't know anything much really and I have few ideas on how to fix this. I am beginning to suspect that it is my redirect method but I have no idea how to do it differently. I'd be really grateful if someone could explain what I'm doing wrong here, this is for my personal family site and I want it to be good. It took me a week to do the login! What I'd love to achieve is exactly the same as the attachment box(es) right below where I am typing now. I have attached my two relavent pages. Thanks in advance. Paul [attachment deleted by admin] Hi. I have the following code: <?php $host=""; $username=""; $password=""; $db_name=""; $tbl_name="topic"; // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $name=$_POST['name']; $detail=$_POST['details']; $sql="INSERT INTO $tbl_name(topic, detail, datetime)VALUES('$name', '$detail', NOW())"; $result=mysql_query($sql); if($result){ echo("Topic created. "); $sql3="SELECT max(id) FROM $tbl_name"; $result3=mysql_query($sql3); $tbl_name2="top_img"; for($i=1; $i<11; $i++){ $uploaddir = '/imgs/'; $uploadfile = $uploaddir . basename($_FILES['img'.$i]['name']); echo '<pre>'; if (move_uploaded_file($_FILES['img'.$i]['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; } }} echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; echo("<br><br><a href='site.html'>HOME</a>"); ?> And the error message: Quote Topic created. PHP Error Message Warning: move_uploaded_file(/imgs/Sunset.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/a7129718/public_html/test/add_topic.php on line 28 PHP Error Message Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php73HyFd' to '/imgs/Sunset.jpg' in /home/a7129718/public_html/test/add_topic.php on line 28 Free Web Hosting Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Here is some more debugging info:Array ( [img1] => Array ( [name] => Sunset.jpg [type] => image/jpeg [tmp_name] => /tmp/php73HyFd [error] => 0 [size] => 71189 ) [img2] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 bla bla bla Any idea what the problem might be? Thanks in advance. Bye. I am trying to uploading images when i submit the images i get an error Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6 How do i fix this my code is below. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>upload</title> </head> <body> <?php //connect to MySQL $db = mysql_connect('localhost', 'user', 'pass') or die ('Unable to connect. Check your connection parameters.'); mysql_select_db('testdb', $db) or die(mysql_error($db)); //change this path to match your images directory $dir ='productimages'; //change this path to match your thumbnail directory $thumbdir = $dir . 'productthumb'; //change this path to match your fonts directory and the desired font putenv('GDFONTPATH=' . 'C:/Windows/Fonts'); $font = 'arial'; // handle the uploaded image if ($_POST['submit'] == 'Upload') { //make sure the uploaded file transfer was successful if ($_FILES['uploadfile']['error'] != UPLOAD_ERR_OK) { switch ($_FILES['uploadfile']['error']) { case UPLOAD_ERR_INI_SIZE: die('The uploaded file exceeds the upload_max_filesize directive ' . 'in php.ini.'); break; case UPLOAD_ERR_FORM_SIZE: die('The uploaded file exceeds the MAX_FILE_SIZE directive that ' . 'was specified in the HTML form.'); break; case UPLOAD_ERR_PARTIAL: die('The uploaded file was only partially uploaded.'); break; case UPLOAD_ERR_NO_FILE: die('No file was uploaded.'); break; case UPLOAD_ERR_NO_TMP_DIR: die('The server is missing a temporary folder.'); break; case UPLOAD_ERR_CANT_WRITE: die('The server failed to write the uploaded file to disk.'); break; case UPLOAD_ERR_EXTENSION: die('File upload stopped by extension.'); break; } } |