Hi guys,
I’ve been writing a simple form with user input and file upload abilities.
Everything was working okay… kind of. I can capture all of the users info, file uploading is working for the image field but not the CV field. Also, when images are saved on the server, I cannot open them?
Here is my form:
and here is my PHP code (please note I’m no expert, my code may be messy).
Why can I not capture both the image and CV? Also, is it possible to add checks for type etc?
[php] <?php
ini_set(‘display_errors’,1);
error_reporting(E_ALL);
?>
<?php include ('connect.php'); //This is the directory where images will be saved $target = "images/"; $target = $target . basename( $_FILES['photo']['name']); //This is the directory where images will be saved $target2 = "cv/"; $target2 = $target2 . basename( $_FILES['cv']['name']); // Get values from form $first_name = $_POST['first_name']; $surname = $_POST['surname']; $address_line_1 = $_POST['address_line_1']; $address_line_2 = $_POST['address_line_2']; $city = $_POST['city']; $post_code = $_POST['post_code']; $country = $_POST['country']; $date_of_birth = $_POST['date_of_birth']; $interests = $_POST['interests']; $height = $_POST['height']; $chest_size = $_POST['chest_size']; $waist_size = $_POST['waist_size']; $inside_leg_size = $_POST['inside_leg_size']; $outside_leg_size = $_POST['outside_leg_size']; $shoe_size = $_POST['shoe_size']; $female_dress_size = $_POST['female_dress_size']; $passport = $_POST['passport']; $driving_license = $_POST['driving_license']; $pic = ($_FILES['photo']['name']); $cv = ($_FILES['cv']['name']); // Insert data into mysql $sql="INSERT INTO $tbl_name(first_name, surname, address_line_1, address_line_2, city, post_code, country, date_of_birth, interests, height, chest_size, waist_size, inside_leg_size, outside_leg_size, shoe_size, female_dress_size, passport, driving_license, photo, cv)VALUES('$first_name', '$surname', '$address_line_1', '$address_line_2', '$city', '$post_code', '$country', '$date_of_birth', '$interests', '$height', '$chest_size', '$waist_size', '$inside_leg_size', '$outside_leg_size', '$shoe_size', '$female_dress_size', '$passport', '$driving_license', '$pic', '$cv')"; $result=mysql_query($sql); //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your photo."; } // ---------------------------- // //Writes users cv to the server if(move_uploaded_file($_FILES['cv']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['cv']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your cv."; } // ---------------------------- // // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo ""; echo "Back to main page"; } else { echo "ERROR"; } ?> <?php // close connection mysql_close(); ?> [/php]