PHP - Upload Problem
Hey Guys, can somebody please have alook at my code, when I don't have the mysql stuff in it works not problem, when I add the mysql it does not want to upload the file.
Thanks Code: [Select] <?php // Where the file is going to be placed $target_path = "../uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { { $con = mysql_connect("localhost","******", "*******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("******", $con); mysql_query("INSERT INTO table (sname, smonth, sday, syear, sdload) VALUES ('$sname', '$smonth', '$sday', '$syear', '$fileupload')"); mysql_close($con); echo "Successful<BR/>"; echo "<a href=index2.php>Return to admin section</a>"; } } else{ echo "There was an error uploading the file, please try again!"; } ?> Similar TutorialsHi Everyone, I have a small problem and try to learn from all the help i get here. I have a form that gathers info, emails and inserts info into the database, everything works fine except the file doesnt upload and the file name does not go into the database, instead i get /recruitment in the file field of the databse, instead of recruitment/uploadedfile.pdf Code Below, please help, <?php switch ($_REQUEST['action']) { case 'recruit': foreach($_POST as $key=>$value){ $$key = $value; } if ((!$name) || (!$email) || (!$phone)) { $error_msg = 'Fields marked<span class="gold"> * </span>are required to submit the form'; }elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $error_msg = 'Invalid email address'; } echo "$error_msg","<br><br>"; if ($error_msg == ''){ $add="recruitment/".$_FILES[userfile][name]; $cleaned = stripit($add); $add2 = "../".$cleaned; move_uploaded_file ($_FILES[userfile][tmp_name], $add2); $Q = mysql_query("INSERT INTO recruitment (`name`,`phone`,`email`, `qual`,`exper`,`file`) VALUES ('$name','$phone','$email','$qual','$exper','$cleaned')"); foreach($_POST as $key=>$value){ $$key = htmlentities(stripslashes($value)); } $companyname = 'Business college'; $companyemail = 'ross@emediastudios.com.au'; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: ".$name." <".$email.">\r\n"; $headers .= "Reply-To: ".$name." <".$email.">\r\n"; $to = "".$companyname."<".$companyemail.">"; $subject = "Business College Recruitment Form Submission"; $message = '<style type="text/css>"; <!-- .style { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; } --> </style> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="style"> <b>Details:</b><br /><br /> <b>Name:</b> '.$name.'<br /> <b>Email:</b> '.$email.'<br /> <b>Mobile No:</b> '.$phone.'<br /> <b>Qualifications:</b><br> '.$qual.'<br /> <b>Experience:</b><br /><br />'.$exper.'<br /><br /> <b>Uploaded resume:</b> http://www.mydomain.com.au/'.$cleaned.' </td> </tr> </table>'; mail($to, $subject, $message, $headers); echo '<table width="99%" border="0" cellpadding="0" cellspacing="0"> <tr> <td class="mybody">Hi '.$name.',<p />Thank you for your enquiry. An Consultant will contact you shortly.<br /> <br /> </td> </tr> </table>'; }else{ foreach($_POST as $key=>$value){ $$key = htmlentities(stripslashes($value)); } echo ' <form id="form" name="Contact Form" method="post" action="'.$_SERVER['PHP_SELF'].'?action=recruit"> <table width="489" border="0" cellspacing="5" cellpadding="0"> <tr> <td width="227">Name:</td> <td width="358"><input type="text" name="name" id="name" value="'.$name.'" /></td> </tr> <tr> <td>Contact Mobile:</td> <td><input type="text" name="phone" id="phone" value="'.$phone.'" /></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email" id="email" value="'.$email.'" /></td> </tr> <tr> <td>Relevent Qualifications:</td> <td><textarea name="qual" id="qual" cols="45" rows="5" value="'.$qual.'"></textarea></td> </tr> <tr> <td>Recent Experience:</td> <td><textarea name="exper" id="exper" cols="45" rows="5" value="'.$exper.'"></textarea></td> </tr> <tr> <td>Upload Resume:</td> <td><input type="file" name="userfile" id="userfile" /></td> </tr> <tr> <td><input type="submit" name="submit" id="submit" value="Submit" /></td> <td> </td> </tr> </table> </form>'; } break; } ?> When I upload files larger than appx 18M it says that the file was uploaded but it isnt. Is there snippet of code that i could put in the script to show me the upload error ? Or does anyone know what could be causing this. My php.ini settings are as follows max upload size = 50M max post size = 100M execution time = 2400 input time = 2400 I thought initially maybe it was timing out so i increased the input and the execution time value. But its still doing the same thing. -SB I have a wierd issue that I cant quite pin down. Here is my code Code: [Select] if(isset($_GET['world']) && ($_GET['world'] == "upload")) { $foldername = $_POST['worldname']; $target = "worlduploads/"; $ok=1; $allowed_types = array("application/octet-stream","application/zip","application/x-zip"); $allowed_extensions = array("zip"); if ($_FILES['file']['size'] > 262144000) { $max_size = round(25600); echo "Your file is too large. Maximum file size is 250MB. <br>"; $ok=0; } if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; $ok=0; } else { $path_parts = pathinfo(strtolower($_FILES["file"]["name"])); if(in_array($_FILES["file"]["type"],$allowed_types) && in_array($path_parts["extension"],$allowed_extensions)) { $filename = $_FILES["file"]["name"]; } else { echo "Type " . $_FILES["file"]["type"] . " with extension " . $path_parts["extension"] . " not allowed <br />"; $ok=0; } } if($ok == 1) { move_uploaded_file($_FILES["file"]["tmp_name"], $target . $filename); $file_location = $target . $filename; if(file_exists($file_location)) { mkdir('worlduploads/'.$foldername.''); //create local $dir = 'worlduploads/'.$foldername.'/'; $zip = zip_open($file_location); while($zip_entry = zip_read($zip)) { $entry = zip_entry_open($zip,$zip_entry); $filename = zip_entry_name($zip_entry); $target_dir = $dir.substr($filename,0,strrpos($filename,'/')); $filesize = zip_entry_filesize($zip_entry); if (is_dir($target_dir) || mkdir($target_dir)) { if ($filesize > 0) { $contents = zip_entry_read($zip_entry, $filesize); file_put_contents($dir.$filename,$contents); } } } } else { echo "There was a problem saving the file. <br />"; } } } The idea is, the user enters a file name and upload there zip file, once uploaded this then unzips to a specified directory. This works fine if all the files are contained within the root of the zip, however if I try to upload a zip that contains folders then I just get Error: 1 displayed. I removed the unzip function and this is happening with just the upload. I would have thought that php would just copy the zip byte by byte without investigating its structure? I have tested my unzip with zips that contain folders and it works fine, maintains structure and puts the files where it should, its just the upload error that is giving me problems! PHP.ini is also set to 250mb Thanks for any insights hello everyone....i am new for this script, hope u guys able to help me. Thank you in advance! im using xampp for localhost, all .php file i place it in xampp\htdocs ( i create a uploads folder outside the htdocs, c:\xampp\uploads) This is the error message i get after i upload the file: Notice: Undefined variable: FILES in C:\xampp\htdocs\upload_file.php on line 15 Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in C:\xampp\htdocs\upload_file.php on line 15 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\phpAE.tmp' to '../uploads/' in C:\xampp\htdocs\upload_file.php on line 15 Your file could not be uploaded because: Something unforeseen happened.. following is my upload_file.php script , i highlighted on line 15: <!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>Upload a File</title> </head> <body> <?php ///Script - 11.4 - upload_file.php /* This script displays and handles an HTML form. this script takes a file upload and stored it on the servers */ if(isset($_POST['submitted'])) { //Handle the form //Try to move the upload file: if (move_uploaded_file ($_FILES['thefile']['tmp_name'],"../uploads/{$FILES['thefile']['name']}")){ print '<p>Your file has been uploaded.</p>'; }else { //problem!! print '<p style="color:red;">Your file could not be uploaded because: '; ///print a message based upon the error: switch ($_FILES['thefile']['error']) { case 1: print 'The file exceeds the upload_max_filesize setting in php.ini'; break; case 2: print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form'; break; case 3: print 'The file was only partially uploaded'; break; case 4: print 'No file was uploaded'; break; case 6: print 'The temporary folder does not exist.'; break; default: print 'Something unforeseen happened.'; break; } print '.</p>'; /////complete the paragraph. } // End of move_uploaded_file()IF } // End of submission IF //Leave PHP and display the form: ?> <form action="upload_file.php" enctype="multipart/form-data" method="post"> <p>Upload a file using this form:</p> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <p><input type="file" name="thefile" /></p> <p><input type="submit" name="submit" value="Upload This File" /></p> <input type="hidden" name="submitted" value="true" /> </form> </body> </html> this script is supposed to save my $csvfile to a .sql file name $ouputfile into a folder called files/ $csvfile = $_FILES['file']['name']; //form from another folder $save = 1; $outputfile = "output.sql"; here is the save script if($save) { chmod($csvfile, 0777); if(!is_writable($outputfile)) { echo "File is not writable, check permissions.\n"; //when i execute this script, it goes in here } else { $file2 = fopen($outputfile,"w"); if(!$file2) { echo "Error writing to the output file.\n"; } else { fwrite($file2,$queries); fclose($file2); } } hi i have wrote this code for uploading an image this is my main code <?php $lastimage2 = mysql_query("SELECT * FROM images WHERE id=$view"); $li2 = mysql_fetch_assoc($lastimage2); if ($page=="P8"&$view>0) { echo "<table class=roung bgcolor='#000000'><tr><TD><img src=uploaded/$li2[picname] width='760' height='540'></td></tr></table>"; include 'picclicks.php'; echo "<tr><td>Views: $clicks2 </td></tr>"; } else { if ($_SESSION['user']) { If ($imagereport='1') { } echo" <table bgcolor='#000000' class=round><tr><td class=ach> <form action='index.php?variable=".$page."&fun=upload' method='POST' enctype='multipart/form-dat'> <input type='file' name='myfile'> <input type='submit' value='Upload'> </td></tr></table></form> "; } else { echo "Please Login to upload new photos!"; } ?> then i have this for imageupload.php <?php if ($_FILES) { $username = $_SESSION['user']; $date =time(); $name = $_FILES["myfile"]["name"]; $type = $_FILES["myfile"]["type"]; $size = $_FILES["myfile"]["size"]; $temp = $_FILES["myfile"]["tmp_name"]; $error = $_FILES["myfile"]["error"]; $hs=$_POST['High Score']; $g=$_POST['Glitch']; $f=$_POST['Funny']; $o=$_POST['Other']; $tags = new Array(); foreach($_POST['tag'] as $tag){ if($tag){ tags[] = $tag; } } $tag = implode(',',$tags); if ($error > 0 ) die("Error uploading file! Code $error."); else { if ($type =="image/jpeg") { include 'connect.inc'; move_uploaded_file($temp,"uploaded/".$name); mysql_query("INSERT INTO images VALUES('','$name','','$username','$date','0','0','0','0','0','0','0','0')"); $uploadreport='1'; } else { } } } else { } ?> my database is set right, and this is what i have in my index file if ($fun=="upload") { include 'imageupload.php'; } when i click upload it directs it to index.php?variable=P8&fun=upload but nothing shows up on screen if u need more details please ask cheers matt I am working on a file upload that stores the image in the database. my upload field is this: Code: [Select] <input type="file" name="image1[]" /> and my php to process the file and upload it is this: $maxsize = 100000; if(is_uploaded_file($_FILES['image1']['tmp_name'])) { //check the file is less than the maximum file size if($_FILES['image1']['size'] < $maxsize) { //prepare the image for insertion $imgData =addslashes(file_get_contents($_FILES['image1']['tmp_name'])); $imgData = addslashes($_FILES['image1']); //get the image info.. $size = getimagesize($_FILES['image1']['tmp_name']); $id = $name.'_'.$SKU; //our sql query $sql = "INSERT INTO Images ( imageID , Type ,Image, Size, FileName, DateAdded, Category, SKU. Description) VALUES ('".$id."', '".$size['mime']."', '".$imgData."', '".$size[3]."', '".$_FILES['image1']['name']."', NOW(), Fabric, '".$SKU."', '".$desc."'"; echo $sql; // insert the image if(!mysql_query($sql)) { echo 'Unable to upload file'; } } } else { // if the file is not less than the maximum allowed, print an error echo '<div>File exceeds the Maximum File limit</div> <div>Maximum File limit is '.$maxsize.'</div> <div>File '.$_FILES['image1']['name'].' is '.$_FILES['image1']['size'].' bytes</div> <hr />'; } at first the sql just wouldn't work. Now I get this error every time for some reason Quote File exceeds the Maximum File limit Maximum File limit is 100000 File Array is Array bytes which seems odd because it does not even return the file size or name correctly. Hi Guys I have this PHP Upload Scripts below which uploads file of customers into the customers folder and at the same time inserts the file path into the database. The problems is for name like O'hare or O'neil its uploads into the customers folder but does not insert the file path into the database - probably because of the " ' " apostrophe From the code below is there anyway I can deal with this issue? Thanks alot Code: [Select] <?php //This php block of code will takecare of inserting the upload variables into the db if(isset($_POST['submitbutton'])) { $target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/'; $target_path = $target_path . basename( $_FILES['upload']['name']); $manager= mysql_real_escape_string($_POST['username']); $upload = $_FILES['upload']['name']; $check_id = mysql_real_escape_string($_POST['id']); $submitbutton= mysql_real_escape_string($_POST['submitbutton']); if($submitbutton) { if($manager&&$upload) { if (file_exists($target_path)) { echo $_FILES["upload"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["upload"]["tmp_name"],$target_path); echo "Stored in: " . 'customerUploads/' . $check_id . ', ' . $c_name . '/' . $_FILES["upload"]["name"]; $insert=mysql_query("INSERT INTO img_up (username,upload,id,target_path,img_date) VALUES ('$manager','$upload','$check_id','$target_path', now()) "); // Where the file is going to be placed $target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/'; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['upload']['name']); $target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/'; $target_path = $target_path . basename( $_FILES['upload']['name']); if (file_exists($target_path)) { echo $_FILES["upload"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["upload"]["tmp_name"],$target_path); echo "Stored in: " . 'customerUploads/' . $check_id . ', ' . $c_name . '/' . $_FILES["upload"]["name"]; } } } else { echo "There was an error uploading the file, please try again!"; } } header("location: mainupload_complete.php?id=$check_id"); } ?> Hi All, I have a code to upload a file to the server. Somehow the files don't get uploaded, although the record is add to the database. I have no clue why it doesn't work. The settings of the folder where the docs goto is set to 777. Code: [Select] <?php $uploaddir = "documents/"; $path = $uploaddir.$document; //This function reads the extension of the file. $allowedExtensions = array("doc", "pdf", "xls"); function isAllowedExtension($fileName) { global $allowedExtensions; return in_array(end(explode(".", $fileName)), $allowedExtensions); } if($document != ""){ //AS LONG AS A FILE WAS SELECTED... //compare the size with the maxim size we defined and print error if bigger $fsize=filesize($_FILES['document']['tmp_name']); if (($fsize/1024) > $poidsMax*1024) { $msgToUser = '<br /><br /><font color="#FF0000">You exceeded the filesize limit. Document did not get posted.</font>'; include_once 'msgToUser.php'; $errors=1; } if(isAllowedExtension($HTTP_POST_FILES['document']['tmp_name'])) { if(copy($HTTP_POST_FILES['document']['tmp_name'], $path)){ //IF IT HAS BEEN COPIED... //GET FILE NAME $theFileName = $HTTP_POST_FILES['document']['name']; //GET FILE SIZE $theFileSize = $HTTP_POST_FILES['document']['size']; if ($theFileSize>999999){ //IF GREATER THAN 999KB, DISPLAY AS MB $theDiv = $theFileSize / 1000000; $theFileSize = round($theDiv, 1)." MB"; //round($WhatToRound, $DecimalPlaces) } else { //OTHERWISE DISPLAY AS KB $theDiv = $theFileSize / 1000; $theFileSize = round($theDiv, 1)." KB"; //round($WhatToRound, $DecimalPlaces) } } else { $msgToUser = '<br /><br /><font color="#FF0000">Ooops something went wrong.</font><p><a href="../index.php">Go Back</a></p>'; include_once 'msgToUser.php'; $errors=1; } } } $name = strip_tags($name, ''); $message = strip_tags($message, ''); $sql = mysql_query("INSERT INTO bulletin_board (posting_date, member_id, title, subject, picture, document) VALUES(now(),'$logOptions_id', '$name','$message', '$image_name', '$theFileName')") or die (mysql_error()); Marco I have a page for image uploads and I just realized it will only work if a user already has on picture uploaded. If they don't it won't work. The ones that do fail some photos anyway which is probably that they don't pass the image check but when I put echoes in there to trace what happens any user with an empty gallery can't upload a photo because the page says there is no file in the $_FILES['image']['name'] variable. Here are the initial conditions and the form (leaving out the image processing etc since that works): Code: [Select] if (!isset($_SESSION['user'])) die("<br /><br /> You need to log in to view this page"); $user = sanitizeString($_SESSION['user']); $view = sanitizeString($_GET['view']); $dir = './grafik/users/'.$user.'/big/'; $files = scandir($dir); $len = count($files); $nr= $len-1; $maxPhotos = 8; if ($view == $user) { echo "view is user"; if(!file_exists("grafik/users/$user")) { mkdir("grafik/users/$user"); mkdir("grafik/users/$user/big/");} } if (!isset($_FILES['image']['name'])) echo "There is no file <br />$dir - $user - $nr"; if (isset($_FILES['image']['name'])) { echo "<br />...is a file <br />$dir - $user - $nr"; $photoName="$dir$user$nr.jpg"; move_uploaded_file($_FILES['image']['tmp_name'], $photoName); $typeok = TRUE; .... <form method='post' action='gallery.php?view=$user' enctype='multipart/form-data'> Upload another photo: <br /> Max $maxPhotos allowed, max filesize 2Mb <br /> <input type='file' name='image' size='10' /><br /> <input type='submit' value='Upload' /> </form> I can't see why it wouldn't let me but I have a feeling someone here knows why. Hello,
I have the following upload script that actually worked until I tried to add file type specifications. I can't figure out what I did wrong. I have been piecing things together so there is no telling what is wrong. Help me please?
<?php $fileName = $_FILES["file1"]["name"]; // The file name $fileTmpLoc = $_FILES["file1"]["tmp_name"]; // File in the PHP tmp folder $fileType = $_FILES["file1"]["type"]; // The type of file it is $fileSize = $_FILES["file1"]["size"]; // File size in bytes $fileErrorMsg = $_FILES["file1"]["error"]; // 0 for false... and 1 for true if (!$fileTmpLoc) { // if file not chosen echo "ERROR: Please browse for a file before clicking the upload button."; exit(); } if ($fileType=="image/png" || $fileType=="image/gif" || $fileType=="image/jpg") // checking file type echo "ERROR: Only file types .png, .gif or .jpg may be uploaded"; exit(); } if(move_uploaded_file($fileTmpLoc, "image_uploads/$fileName")){ echo "$fileName upload is complete"; } else { echo "move_uploaded_file function failed"; } ?>Thanks. I've Got here a code.. it can upload pdf file. but it doesnt accept word documents and powerpoints And i dont know the problem.. Here's The code.. Code: [Select] <?php session_start(); if(isset($_SESSION['uname2'])){ if($_POST['lesson']!=""){ if (($_FILES["Mapfile"]["type"] == "application/acrobat") ||($_FILES["Mapfile"]["type"] == "application/x-pdf") || ($_FILES["Mapfile"]["type"] == "application/pdf") || ($_FILES["Mapfile"]["type"] == "text/pdf") || ($_FILES["Mapfile"]["type"] == "application/powerpoint") || ($_FILES["Mapfile"]["type"] == "application/msword") || ($_FILES["Mapfile"]["type"] == "text/x-pdf") && ($_FILES["Mapfile"]["size"] < 50000)) { if ($_FILES["Mapfile"]["error"] > 0) { echo "Error: " . $_FILES["Mapfile"]["error"] . "<br />"; } else { if (file_exists("upload/" . $_FILES["Mapfile"]["name"])) { echo '<script type="text/javascript"> {alert("'.$_FILES["Mapfile"]["name"] .' already exist");} </script>'; echo '<meta http-equiv="REFRESH" content="0;url=uploadlesson.php">'; } else { move_uploaded_file($_FILES["Mapfile"]["tmp_name"], "upload/" . $_FILES["Mapfile"]["name"]); echo '<script type="text/javascript"> {alert("File Uploaded!");} </script>'; echo '<meta http-equiv="REFRESH" content="0;url=uploadlesson.php">'; $host="localhost"; $username="root"; $password=""; $db_name="dbprof"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $user = $_SESSION['uname2']; $sql="SELECT * FROM registeredprof where Username = '$user'"; $result=mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $fullname = $row['fullname']; } $title = $_POST['lesson']; $filename = $_FILES['Mapfile']['name']; mysql_query("INSERT INTO lessondb (author, title, filename, status) VALUES ('$fullname', '$title', '$filename', 'offline')"); } } } else { echo '<script type="text/javascript"> {alert("Invalid File! ");} </script>'; echo '<meta http-equiv="REFRESH" content="0;url=uploadlesson.php">'; } } else { echo '<script type="text/javascript"> {alert("Fill out Title!");} </script>'; echo '<meta http-equiv="REFRESH" content="0;url=uploadlesson.php">'; } } ?> Help pls. I am looking to make an image uploader for my site. I have written the image upload file but its so basic im fearing it will be broken and if someone uploads an image with the same name it will just copy over someone elses. I also need to check that its either jpeg or gif and maybe downsize the image so no one uploads a 5meg phot from a digital camera and crashes the site. Does anyone have any ideas how to do the 3 things above? Hello Im trying to upload mp3s from a form. In the form I have the MAX_FILE_SIZE set at 90000000 (so big to make sure it wasn't my maths). I have checked with phpinfo() and the max upload is set at 8mb. The mp3s will be between 3-4mb in size. I have uploaded small mp3's successfully (440k) so i know the script is working fine, however when i try to upload one at around 3mb it fails, even tried different file sizes in the same ball park size. I suspect the server is blocking them. Any ideas on a fix? Thank you. No script posted as i say its all working. Hi The code below forms part of another piece of code, but I am having problems uploading an image Code: [Select] // Your file name you are uploading $file_name = $logo; // random 4 digit to add to our file name // some people use date and time in stead of random digit $random_digit=rand(0000,9999); //combine random digit to you file name to create new file name //use dot (.) to combile these two variables $new_file_name=$random_digit.$file_name; //set where you want to store files //in this example we keep file in folder upload //$new_file_name = new upload file name //for example upload file name cartoon.gif . $path will be upload/cartoon.gif $path= "logos/".$new_file_name; if($logo !=none) { if(copy($HTTP_POST_FILES['logo']['tmp_name'], $path)) { echo "Successful<BR/>"; //$new_file_name = new file name //$HTTP_POST_FILES['ufile']['size'] = file size //$HTTP_POST_FILES['ufile']['type'] = type of file echo "File Name :".$new_file_name."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; } else { echo "Error"; } } The error messages I am getting are Notice: Undefined variable: logo in C:\wamp\www\wedding_buddy\new_supplier.php on line 27 Notice: Use of undefined constant none - assumed 'none' in C:\wamp\www\wedding_buddy\new_supplier.php on line 43 Notice: Undefined variable: ufile in C:\wamp\www\wedding_buddy\new_supplier.php on line 43 Notice: Undefined variable: HTTP_POST_FILES in C:\wamp\www\wedding_buddy\new_supplier.php on line 45 Warning: copy() [function.copy]: Filename cannot be empty in C:\wamp\www\wedding_buddy\new_supplier.php on line 45 The variable logo is a field from a form, what have I done wrong? Hi, I can't believe after more then a year I'm stuck with the simplest upload script. Here's my code: <?php if( isset($_POST['upload']) ){ $uploaddir = "uploads/"; $uploadfile = $uploaddir.$_FILES['fileupload']['name']; if( move_uploaded_file($_FILES['fileupload']['tmp_name'], $uploadfile) ){ echo "Upload OK!"; }else{ echo "Upload FAILED!!!"; } }else{ ?> <form action="<?php $_SERVER['PHP_SELF'] ?>" name="upload" method="post"> <input type="file" name="fileupload" /> <input type="submit" name="upload" value="upload" /> </form> <?php } ?> this is the simplest php upload script that you can find, though the least secure one (it's for a local pc project). When I try to upload any file it gets to my else statement. Anyone an idea why? I don't see it Thanks! Hi everybody, I have recently change to a new server, and have some problem with a script for uploading files on my new server. Script is an old which I have updated with new php command, <? not accepted in new server. Scripts shall upload picture to folder in server and write information to database From form script I am saving my upload Code: [Select] <input type="hidden" name="Mode" value="EditMapProperty" /> <input type="hidden" name="Old_Map" value="<?php echo $Property->Get_Map();?>" /> In my php script I do elseif($Mode=="EditMapProperty"): $Map_name = $HTTP_POST_FILES['Map']['name']; $Property=new Property($PropertyID); $ReferenceNo=$Property->Get_ReferenceNo(); if($Map!=""): $DeleteMap=$Dir_MapProperty_Admin."".$Property->Get_Map(); @unlink($DeleteMap); endif; if($Map_name==""): $Map=$Old_Map; else: copy($HTTP_POST_FILES['Map']['tmp_name'], $Dir_MapProperty_Admin."".$ReferenceNo."-".$Map_name); $Map=$ReferenceNo."-".$Map_name; endif; $Property->EditMap($Map); //Update database information echo "<meta http-equiv=\"refresh\" content=\"0;URL=$Redirect2?p=property_details&PropertyID=$PropertyID\">"; () Can any help if there are any PHP problem in this coding. Kind Regards Tom Hi Guys, I'm having a problem with some file upload code I wrote and I was wondering if you could help me figure out why it's not working?? Here it is; Code: [Select] if($_POST['photo'] == "") $photo_update = "images/item_pictures/default_item.png"; else { if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 200000000)) { 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 />"; //Check image doesn't exist in first folder then uploads if doesn't. if (file_exists("images/item_pictures/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "images/item_pictures/" . $_FILES["file"]["name"]); echo "Stored in: " . "images/item_pictures/" . $_FILES["file"]["name"]; } //Check image doesn't exist in second*admin*folder then uploads if doesn't. if (file_exists("admin/images/item_pictures/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "admin/images/item_pictures/" . $_FILES["file"]["name"]); $photo_update = "admin/images/item_pictures/" . $_FILES["file"]["name"]; echo "Stored in: " . $uploaded_file; } } } else { echo "Invalid file"; } } Thanks in advance Jacbey Hi Guys First sorry for my bad english. I have a strange problem with php upload form. When i click on submit button ( with uploaded pdf ) nothing happens. The pdf file is 17MB, but with smaller PDF the form works perfectly. Here is the form code: Code: [Select] <form id="pdf" name="pdf" method="post" action="" target="_self" enctype="multipart/form-data" > <p align ="center"> <input type="hidden" name="app_id" value="<?php print $app_id?>"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000000000"> <input type="file" name="file1" value="Upload PDF" device="files" accept="text/pdf" /> <input type="submit" name="sent" value="Send" /> </p> </form> at the beginning of the upload.php i have the following lines: Code: [Select] $sent = isset($_POST['sent']) ? $_POST['sent'] : false; When i debug $sent and $_POST i saw that they are empty : ( With smaller PDF works perfectly but now with 17MB pdf $sent is empty,the result from print_r($_POST) is Array() in php.ini i changed MAX UPLOAD to 20MB and then restarted my apache , but i think this doesn't matter. This problem is very strange : ) Thanks in advance:) Hello, i have an upload form witch i cannot upload pdf it does not recognize the mine pdf type, any help please. here is the code $target_path = $_SERVER['DOCUMENT_ROOT'] . '/admin/upload/'; $target = "upload/".$HTTP_POST_FILES['uploadedfile']['name']; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $fileSize = $_FILES['uploadedfile']['size']; $fileType = $_FILES['uploadedfile']['type']; if ($_FILES['uploadedfile']['size'] > 0) { if (($_FILES["uploadedfile"]["type"] == "image/gif") || ($_FILES["uploadedfile"]["type"] == "image/jpeg") || ($_FILES["uploadedfile"]["type"] == "image/png" ) || ($_FILES["uploadedfile"]["type"] == "application/msword" ) || ($_FILES["uploadedfile"]["type"] == "application/pdf" ) && ($_FILES["uploadedfile"]["size"] < 512000)) { move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path); $query_upload="INSERT INTO upload (upload, chair, id_domeniu, email_1) VALUES ('" . $target . $_FILES['uploadedfile']['name'] . "', '3', '$id_domeniu', '".$_GET['email_1']."')"; $query_upload="UPDATE domenii SET upload='" . $target . $_FILES['uploadedfile']['name'] . "' WHERE email_1='".$email_1."'"; mysql_query($query_upload) or die(mysql_error()); } else { echo "<script language='javascript'>alert('Programul uploadat trebuie sa fie PDF, DOC, JPEG si mai mic de 500 kilobytes.');window.location = 'javascript:history.go(-1)';</script >"; exit(); } } |