ianhaney50 Posted July 14, 2015 Share Posted July 14, 2015 Hi I am trying to get a file uploaded onto the ftp server and get the filepath stored in the mysql database, I have got the location stored in the database but the file is not uploading onto the server, I have tried a .doc file and a .png file and keeps saying the same error Form has been submitted successfully. Warning: move_uploaded_file(candidatescvs/testimonials.png): failed to open stream: No such file or directory in /home/sites/broadwaymediadesigns.co.uk/public_html/sites/recruitment-site/candidates-signup.php on line 88 Warning: move_uploaded_file(): Unable to move '/tmp/phpQgIPaN' to 'candidatescvs/testimonials.png' in /home/sites/broadwaymediadesigns.co.uk/public_html/sites/recruitment-site/candidates-signup.php on line 88 Sorry, there was a problem uploading your file. MySQL error no 1062 : Duplicate entry 'ianhaney' for key 'username' All the data is being saved correctly apart from the dob gets stored as 0000-00-00 in the database but will sort that issue after I can't work out why the file is being uploaded onto the ftp server, the coding is below <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <?php require_once("functions.php"); require_once("db-const.php"); ?> <?php $title = "Candidates Signup - Recruitment Site"; $pgDesc=""; $pgKeywords=""; include ( 'includes/header.php' ); ?> <!--CONTENT--> <?php if (isset($_POST['submit']) && isset($error) == '') { // if there is no error, then process further echo "<p class='success'>Form has been submitted successfully.</p>"; // showing success message ## connect mysql server $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); # check connection if ($mysqli->connect_errno) { echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>"; exit(); } //This is the directory where images will be saved $target = "candidatescvs/"; $target = $target . basename( $_FILES['cvfile']['name']); ## query database # prepare data for insertion $username = mysqli_real_escape_string($mysqli, $_POST['username']); $password = md5($_POST['password']); /*$password = $_POST['password'];*/ $name = mysqli_real_escape_string($mysqli, $_POST['name']); $dob = ($_POST['dob']); $email = mysqli_real_escape_string($mysqli, $_POST['email']); $address1 = mysqli_real_escape_string($mysqli, $_POST['address1']); $address2 = mysqli_real_escape_string($mysqli, $_POST['address2']); $town = mysqli_real_escape_string($mysqli, $_POST['town']); $county = mysqli_real_escape_string($mysqli, $_POST['county']); $postcode = mysqli_real_escape_string($mysqli, $_POST['postcode']); $telnumber = mysqli_real_escape_string($mysqli, $_POST['telnumber']); $mobnumber = mysqli_real_escape_string($mysqli, $_POST['mobnumber']); $worklocation = mysqli_real_escape_string($mysqli, $_POST['worklocation']); $desiredsalary = mysqli_real_escape_string($mysqli, $_POST['desiredsalary']); $currentempstatus = mysqli_real_escape_string($mysqli, $_POST['currentempstatus']); $educationlevel = mysqli_real_escape_string($mysqli, $_POST['educationlevel']); $availableforwork = mysqli_real_escape_string($mysqli, $_POST['availableforwork']); $jobtype = mysqli_real_escape_string($mysqli, $_POST['jobtype']); $cv = ($_FILES['cvfile']['name']); # check if username and email exist else insert // u = username, e = emai, ue = both username and email already exists $exists = ""; $result = $mysqli->query("SELECT username from candidates WHERE username = '{$username}' LIMIT 1"); if ($result->num_rows == 1) { $exists .= "u"; } $result = $mysqli->query("SELECT email from candidates WHERE email = '{$email}' LIMIT 1"); if ($result->num_rows == 1) { $exists .= "e"; } if ($exists == "u") echo "<p><b>Error:</b> Username already exists!</p>"; else if ($exists == "e") echo "<p><b>Error:</b> Email already exists!</p>"; else if ($exists == "ue") echo "<p><b>Error:</b> Username and Email already exists!</p>"; else { # insert data into mysql database $sql = "INSERT INTO `candidates` (`id`, `username`, `password`, `name`, `dob`, `email`, `address1`, `address2`, `town`, `county`, `postcode`, `telnumber`, `mobnumber`, `worklocation`, `desiredsalary`, `currentempstatus`, `educationlevel`, `availableforwork`, `jobtype`, `cvfile`) VALUES (NULL, '{$username}', '{$password}', '{$name}', '{$dob}', '{$email}', '{$address1}', '{$address2}', '{$town}', '{$county}', '{$postcode}', '{$telnumber}', '{$mobnumber}', '{$worklocation}', '{$desiredsalary}', '{$currentempstatus}', '{$educationlevel}', '{$availableforwork}', '{$jobtype}', '{$cv}')"; $result = $mysqli->query($sql); $id = $mysqli->insert_id; //Writes the photo to the server if(move_uploaded_file($_FILES['cvfile']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['cvfile']['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 file."; } $dob = date('Y-m-d', strtotime($_POST['dob'])); if ($mysqli->query($sql)) { $to = $_POST['email']; $subject = "Login Credentials"; $message = "Thank you for signing up, your login information is below \r\n Username: {$_POST['username']} \r\n Password: {$_POST['password']}"; $header = "From:noreply@domain.co.uk \r\n"; $retval = mail ($to,$subject,$message,$header); if( $retval == true ) { echo "Message sent successfully..."; } else { echo "Message could not be sent..."; } redirect_to("candidates-login.php?msg=Registered successfully"); } else { echo "<p>MySQL error no {$mysqli->errno} : {$mysqli->error}</p>"; exit(); } } } ?> <!-- The HTML registration form --> <form method="post" action="<?=$_SERVER['PHP_SELF']?>" enctype="multipart/form-data"> <br /> <label>Upload CV: </label> <input type="hidden" name="size" value="350000"> <input type="file" name="cvfile"> <br /><br /> <input type="submit" name="submit" value="Register" disabled="disabled" id="submitBtn" /> </form> <!--CONTENT--> I took out all the other fields in the form and just left the upload cv coding in the form Quote Link to comment https://forums.phpfreaks.com/topic/297289-upload-file-php-error/ Share on other sites More sharing options...
Ch0cu3r Posted July 14, 2015 Share Posted July 14, 2015 The error is saying it is unable to move the file to the candidatescvs folder. Are you sure a) this is folder exists and b) you have set sufficient file permissions to allow for PHP to write to this directory? Quote Link to comment https://forums.phpfreaks.com/topic/297289-upload-file-php-error/#findComment-1516303 Share on other sites More sharing options...
ianhaney50 Posted July 14, 2015 Author Share Posted July 14, 2015 (edited) Yeah the folder is the on the server, wonder if I should the enter full folder path in the $target line and see if that works but have the exact same script on another site and that works, yeah I have got the permissions set to 755 on the folder Edited July 14, 2015 by ianhaney50 Quote Link to comment https://forums.phpfreaks.com/topic/297289-upload-file-php-error/#findComment-1516304 Share on other sites More sharing options...
ianhaney50 Posted July 14, 2015 Author Share Posted July 14, 2015 I just entered the folder location on the server as the following $target = "http://www.broadwaymediadesigns.co.uk/sites/recruitment-site/candidatescvs/"; when tested again, I get the following error Warning: move_uploaded_file(http://www.broadwaymediadesigns.co.uk/sites/recruitment-site/candidatescvs/testimonials.png): failed to open stream: HTTP wrapper does not support writeable connections in /home/sites/broadwaymediadesigns.co.uk/public_html/sites/recruitment-site/candidates-signup.php on line 88 Warning: move_uploaded_file(): Unable to move '/tmp/phpaIPzdh' to 'http://www.broadwaymediadesigns.co.uk/sites/recruitment-site/candidatescvs/testimonials.png' in /home/sites/broadwaymediadesigns.co.uk/public_html/sites/recruitment-site/candidates-signup.php on line 88 Sorry, there was a problem uploading your file. MySQL error no 1062 : Duplicate entry 'ianhaney' for key 'username' Quote Link to comment https://forums.phpfreaks.com/topic/297289-upload-file-php-error/#findComment-1516308 Share on other sites More sharing options...
Ch0cu3r Posted July 14, 2015 Share Posted July 14, 2015 You cannot use a url as the target. It must be a local file system path, eg /home/user/uploads/candidatescvs/ if you are still getting the error with a full file system path, then double check you have named the folder correctly. Files and folders are case sensitive Quote Link to comment https://forums.phpfreaks.com/topic/297289-upload-file-php-error/#findComment-1516309 Share on other sites More sharing options...
ianhaney50 Posted July 14, 2015 Author Share Posted July 14, 2015 (edited) I am getting somewhere now, I realised I had username and email in the indexes in the phpmyadmin so removed them and tested again but just had candidatecvs/ in the target folder path and got no errors and says registered successfully so is working but the file is not being uploaded on to the server still Edited July 14, 2015 by ianhaney50 Quote Link to comment https://forums.phpfreaks.com/topic/297289-upload-file-php-error/#findComment-1516311 Share on other sites More sharing options...
ianhaney50 Posted July 14, 2015 Author Share Posted July 14, 2015 sorted it doing it with the full path Quote Link to comment https://forums.phpfreaks.com/topic/297289-upload-file-php-error/#findComment-1516312 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.