Jump to content

Form with file upload


dnbmadness

Recommended Posts

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:

 

http://www.soft-links.co.uk/

 

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? The image field should only upload bmp, jpg, jpeg, gifs and pngs. The CV field should only allow doc, docx and PDFs.

 

<?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 "<br>";
echo "<a href='index.php'>Back to main page</a>";
}

else {
echo "ERROR";
}

?>

<?php
// close connection
mysql_close();
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.