have this page which is suppose to check upload is an jpg etc all i get at moment is a blank screen if any one can help cheers Doug <head> <title>Lost and Found Registration</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <?php $correctAnswer = 4; if (isset($_POST['leg']) && $_POST['leg'] != $correctAnswer) { // send em away header("Location: http://www.lostpetsplymouth.com/error-page.html"); exit(); } //This gets all the other information from the form $state=$_POST['state']; $type=$_POST['type']; $area=$_POST['area']; $desc=$_POST['desc']; $name=$_POST['name']; $email=$_POST['email']; $tel=$_POST['tel']; $pnum=$_POST['pnum']; $date = date("d-m-Y"); $pname=$pnum.".jpg"; if ((($_FILES["pic"]["type"] == "image/gif") || ($_FILES["pic"]["type"] == "image/jpeg") || ($_FILES["pic"]["type"] == "image/pjpeg")) && ($_FILES["pic"]["size"] < 20000)) { if ($_FILES["pic"]["error"] > 0) { echo "Return Code: " . $_FILES["pic"]["error"] . "<br />"; } else move_uploaded_file($_FILES['pic']['tmp_name'], 'uploads/'.$pname); } } else { echo "Invalid file"; } // Connects to your Database $dbh=mysql_connect("localhost", "car", "57") or die('I cannot connect to database because: ' .mysql_error()) ; mysql_select_db("cpets"); //Writes the information to the database mysql_query("INSERT INTO `register` VALUES ('$id', '$state', '$type', '$area', '$desc', '$name', '$email', '$tel', '$pname', '$date')"); //compose the mail message $msg= "New Record\n Region: $region, Name: $name, Email: $email "; //send the mail mail('d@gmail.com','New Record',$msg) ?> <?php echo "your information has been added to the directory You will be redirected in three seconds!><br /><br /> <div class='info'>If you don't wish to wait, <a href='index.html'>click here</a>"; echo'<meta http-equiv="REFRESH" content="2;url=index.html">'; ?> </body> </html> PHP:
Hello, Plz replace move_uploaded_file($_FILES['pic']['tmp_name'], 'uploads/'.$pname) with this code if(is_uploaded_file($_FILES['pic']['tmp_name'])) { copy($_FILES['file']['tmp_name'],$'uploads.'/'.$pname); } Hope this is what u need Regards, Stylesofts Developing Team.
replace if (isset($_POST['leg']) && $_POST['leg'] != $correctAnswer) PHP: with if (isset($_POST['leg']) && $_POST['leg'] == $correctAnswer) PHP:
Keep move_uploaded_files, but change the 'uploads/' part to an absolute location => accountname/www/uploads/ -- whatever the path is.
try to put a print_r($_FILES); and check if you see something strange (or post here the results). also be sure the uploads/ directory is writable.
ok lets start again here is my page to upload photo to server works fine what i want to do is only allow jpg file to upload cheers Doug <?php $correctAnswer = 4; if($_POST['leg'] != $correctAnswer) { // send em away header("Location: http://www.lostpetsplymouth.com/error-page.html"); exit(); } //This gets all the other information from the form $state=$_POST['state']; $type=$_POST['type']; $area=$_POST['area']; $desc=$_POST['desc']; $name=$_POST['name']; $email=$_POST['email']; $tel=$_POST['tel']; $pnum=$_POST['pnum']; $date = date("d-m-Y"); $pname=$pnum.".jpg"; move_uploaded_file($_FILES['pic']['tmp_name'], 'uploads/'.$pname); // Connects to your Database $dbh=mysql_connect("localhost", "vcd", "57") or die('I cannot connect to database because: ' .mysql_error()) ; mysql_select_db("pets"); //Writes the information to the database mysql_query("INSERT INTO `register` VALUES ('$id', '$state', '$type', '$area', '$desc', '$name', '$email', '$tel', '$pname', '$date')"); //compose the mail message $msg= "New Record\n Region: $region, Name: $name, Email: $email "; //send the mail mail('d@gmail.com','New Record',$msg) ?> <?php echo "your information has been added to the directory You will be redirected in three seconds!><br /><br /> <div class='info'>If you don't wish to wait, <a href='index.html'>click here</a>"; echo'<meta http-equiv="REFRESH" content="2;url=index.html">'; ?> PHP: or should the code be on the form page?
Use this code: if (!($uploaded_type=="image/jpg")) { echo "You may only upload JPG files.<br>"; $ok=0; } Code (markup):
Hello, Okay so u want to upload only the jpeg images then do like this function getExtension($fileName) { $ext_arr = explode('.',$fileName); $cnt = count($ext_arr); $extension = $ext_arr[$cnt-1]; return $extension; } $extension = getExtension($_FILES['pic']['tmp_name']); if($extension=="jpg" || $extension=="JPG" || $extension=="jpeg" || $extension=="JPEG") { if(is_uploaded_file($_FILES['pic']['tmp_name'])) { copy($_FILES['file']['tmp_name'],$'uploads.'/'.$pname); } } PHP: Now this will work, Regards, Stylesofts Developing Team
Hello, Okay here is the code,plz use this one <?php $dbh=mysql_connect("localhost", "vcd", "57") or die('I cannot connect to database because: ' .mysql_error()) ; mysql_select_db("pets"); function getExtension($fileName) { $ext_arr = explode('.',$fileName); $cnt = count($ext_arr); $extension = $ext_arr[$cnt-1]; return $extension; } $correctAnswer = 4; if($_POST['leg'] != $correctAnswer) { // send em away header("Location: http://www.lostpetsplymouth.com/error-page.html"); exit(); } $extension = getExtension($_FILES['pic']['tmp_name']); if($extension=="jpg" || $extension=="JPG" || $extension=="jpeg" || $extension=="JPEG") { $state=$_POST['state']; $type=$_POST['type']; $area=$_POST['area']; $desc=$_POST['desc']; $name=$_POST['name']; $email=$_POST['email']; $tel=$_POST['tel']; $pnum=$_POST['pnum']; $date = date("d-m-Y"); $pname=$pnum.".jpg"; // Connects to your Database //Writes the information to the database $selectQuery = "INSERT INTO `register` VALUES ('$id', '$state', '$type', '$area', '$desc', '$name', '$email', '$tel', '$pname', '$date')"; $resultSet = mysql_query($seelctQuery); if($resultSet == true) { $msg= "New Record\n Region: $region, Name: $name, Email: $email "; //send the mail mail('d@gmail.com','New Record',$msg)?> <?php echo "your information has been added to the directory You will be redirected in three seconds!><br /><br /> <div class='info'>If you don't wish to wait, <a href='index.html'>click here</a>"; echo'<meta http-equiv="REFRESH" content="2;url=index.html">'; if(is_uploaded_file($_FILES['pic']['tmp_name'])) { copy($_FILES['file']['tmp_name'],'$uploads'.'/'.$pname); } } //compose the mail message } else { echo("Invalid file format, Please upload the image with 'JPEG' type"); } ?> PHP: Now this will work, Regards, Stylesofts Developing Team
sorry to say that i tried it out an gave me error saying not jpeg file when i know it was bug some where cheers Doug