Hello,
I would like some help understanding something to do with the update of my form.
Text fields update fine, images that already exist on my server update fine.
-------but----------------
Images not on my server, do not get added to any of my destination (target) folders. Web browser gives no apparent error messages, and the display pic of the newly added image only displays the Red, Blue and Green image placeholder. - no image?
I believe it to be something to do with the target folders however im asking for some guidance/advice on what?
Firstly my page with the form, where users choose to change the image/display pic:
View01.php:
[code]<?PHP
ini_set(‘display_errors’,1);
error_reporting(E_ALL);
session_start();
if(!isset($_SESSION[‘id’]) || !isset($_SESSION[‘valid_user’]) || $_SESSION[‘valid_user’] != “yes”) {
$_SESSION = array();
session_destroy();
header(“Location: index.php”);
exit();
}
include (‘php only scripts/db.php’);
$id = $_GET[‘id’];
$query =“SELECT * FROM companies WHERE id = ‘$id’”;
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
?>
Removalspace.com
e.g first two letters and number: i.e: AA1 or AA12
About |
Contact |
Your Logo: |
email: " . $row['email'] . " website: " . $row['website'] ; ?> |
if (preg_match($pattern, $postcode)) {
return TRUE;
}
$this->validation->set_message('is_valid_uk_postcode', 'That is not a valid %s.');
return FALSE;
}
/* FUNCTION TO CREATE SALT /
function createSalt() {
$string = md5(uniqid(rand(), true));
return substr($string, 0, 3);
}
/ check if form was submitted /
if (isset($_POST[‘Submit’])){
$error_message = “”;
/ This is the directory where images will be saved /
$target = “/home/users/web/b109/ipg.removalspacecom/images/COMPANIES/”;
$target = $target . basename( $_FILES[‘upload’][‘name’]);
/ include validation script /
include (‘php only scripts/validation.php’);
$uploadDir = ‘images/COMPANIES’; / main picture folder /
$max_height = 450; / largest height you allowed; 0 means any /
$max_width = 450; / largest width you allowed; 0 means any /
$max_file = 2000000; / set the max file size in bytes /
$image_overwrite = 1; / 0 means overwite; 1 means new name /
/ add or delete allowed image types /
$allowed_type01 = array( “image/gif”, “image/pjpeg”, “image/jpeg”, “image/png”, “image/x-png”, “image/jpg”);
$do_thumb = 1; / 1 make thumbnails; 0 means do NOT make /
$thumbDir = “/images/thumbs”; / thumbnail folder /
$thumb_prefix = “”; / prefix for thumbnails /
$thumb_width = 90; / max thumb width /
$thumb_height = 70; // max thumb height
//Writes the photo to the server
if(move_uploaded_file($_FILES[‘upload’][‘tmp_name’], $target)) {
/ HERE IS WHERE WE WILL DO THE ACTUAL RESIZING /
/ THESE SIX PARAMETERS MAY BE CHANGED TO SUIT YOUR NEEDS /
$upload = $_FILES[‘upload’][‘name’];
$o_path =“images/COMPANIES/”;
$s_path = “images/thumbs/”;
$file = $upload;
$save = $file;
$t_w = 200;
$t_h = 150;
/ DO NOT CHANGE THIS NEXT LINE /
Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path);
}else{
//Gives and error if its not
$error_message .= “Sorry, there was a problem uploading your file.”;
}
/ PREPARE DATA FOR INSERTION INTO TABLE */
//Writes the information to the database
if(strlen(trim($error_message)) <1){
$salt = createsalt();
$username = trim($_POST[‘username’]);
$password = trim($_POST[‘password’]);
$hash = hash(‘sha256’, $salt, $password);
$approved = 0;
$company_name = mysql_real_escape_string(trim($_POST[‘company_name’]));
$website = mysql_real_escape_string(trim($_POST[‘website’]));
$contact_name = mysql_real_escape_string(trim($_POST[‘contact_name’]));
$location = mysql_real_escape_string(trim($_POST[‘location’]));
$postcode = mysql_real_escape_string(trim($_POST[‘postcode’]));
$street1 = mysql_real_escape_string(trim($_POST[‘street1’]));
$street2 = mysql_real_escape_string(trim($_POST[‘street2’]));
$city = mysql_real_escape_string(trim($_POST[‘city’]));
$phone = mysql_real_escape_string(trim($_POST[‘phone’]));
$phone2 = mysql_real_escape_string(trim($_POST[‘phone2’]));
$email = mysql_real_escape_string(trim($_POST[‘email’]));
$premiumuser_description = mysql_real_escape_string(trim($_POST[‘premiumuser_description’]));
$salt = mysql_real_escape_string($salt);
$upload = mysql_real_escape_string($upload);
$query =“INSERT INTO companies
(company_name, what_services, website, contact_name, location, postcode, street1, street2, city, phone,phone2, email, premiumuser_description, username, password, salt, approved, upload) VALUES (’$company_name’, ‘$what_services’, ‘$website’, ‘$contact_name’, ‘$location’, ‘$postcode’, ‘$street1’, ‘$street2’, ‘$city’, ‘$phone’, ‘$phone2’, ‘$email’, ‘$premiumuser_description’, ‘$username’, ‘$hash’, ‘$salt’, ‘$approved’, ‘$upload’)”;
$result = mysql_query($query) or die(mysql_error());
if ($result) {
}
/* at this point we can send an email to the admin as well as the user. DO NOT send the user's password to ANYONE!!!! */
}
}//if (isset($_POST[‘submit’]))
?>
Edit Your detailsfill out the form with your details... |
|
Click submit to update...
|
|
|
|
Website: |
|
Primary Number: |
|
Secondary Number: |
|
Company Description: |
Write a description of what your company does, the services it offers and any additional information here.
|
Images: |
Upload your company image here.
|
|
|
Secondly view02.php processes the form’s data to use UPDATE.
View02.php:
[code]<?php
include (‘php only scripts/db.php’);
include(‘php only scripts/resize.php’);
$id = intval($_GET[‘id’]); // guarantee it’s a harmless number value
if (isset($_GET[‘website’]) && $_GET[‘website’]) { // does the GET value exists and has it a value ?
$website = mysql_real_escape_string($_GET[‘website’]); // get its value and escape it
$setArray[] = “website = ‘$website’”; // ok to update this field in the query so store it
}
if (isset($_GET[‘phone’]) && $_GET[‘phone’]) {
$phone = mysql_real_escape_string($_GET[‘phone’]);
$setArray[] = “phone = ‘$phone’”;
}
if (isset($_GET[‘phone2’]) && $_GET[‘phone2’]) {
$phone2 = mysql_real_escape_string($_GET[‘phone2’]);
$setArray[] = “phone2 = ‘$phone2’”;
}
if (isset($_GET[‘premiumuser_description’]) && $_GET[‘premiumuser_description’]) {
$premiumuser_description = mysql_real_escape_string($_GET[‘premiumuser_description’]);
$setArray[] = “premiumuser_description = ‘$premiumuser_description’”;
}
if (isset($_GET[‘username’]) && $_GET[‘username’]) {
$username = mysql_real_escape_string($_GET[‘username’]);
$setArray[] = “username = ‘$username’”;
}
if (isset($_GET[‘password’]) && $_GET[‘password’]) { // These are the same so you’d need to make them different if your comparing the password to ensure they entered it correctly ex: $_GET[‘password1’] for another field in your form
$password= mysql_real_escape_string($_GET[‘password’]); // This is fine if the 2 values above are first compared
$setArray[] = “password = SHA(’$password’)”; // If they are compared and validation checks out then just do the query to update the password here…
}
if (isset($_GET[‘upload’]) && $_GET[‘upload’]) {
$upload = mysql_real_escape_string($_GET[‘upload’]);
$setArray[] = “upload = ‘$upload’”;
}
/* check if form was submitted /
if (isset($_POST[‘Submit’])){
$error_message = “”;
/ This is the directory where images will be saved /
$target = “/home/users/web/b109/ipg.removalspacecom/images/COMPANIES/”;
$target = $target . basename( $_FILES[‘upload’][‘name’]);
/ include validation script /
include (‘php only scripts/validation.php’);
$uploadDir = ‘/home/users/web/b109/ipg.removalspacecom/images/COMPANIES’; / main picture folder /
$max_height = 450; / largest height you allowed; 0 means any /
$max_width = 450; / largest width you allowed; 0 means any /
$max_file = 2000000; / set the max file size in bytes /
$image_overwrite = 1; / 0 means overwite; 1 means new name /
/ add or delete allowed image types /
$allowed_type01 = array(“image/gif”, “image/pjpeg”, “image/jpeg”, “image/png”, “image/x-png”, “image/jpg”);
$do_thumb = 1; / 1 make thumbnails; 0 means do NOT make /
$thumbDir = “/home/users/web/b109/ipg.removalspacecom/images/thumbs”; / thumbnail folder /
$thumb_prefix = “”; / prefix for thumbnails /
$thumb_width = 90; / max thumb width /
$thumb_height = 70; // max thumb height
//Writes the photo to the server
if(move_uploaded_file($_FILES[‘upload’][‘tmp_name’], $target)) {
/ HERE IS WHERE WE WILL DO THE ACTUAL RESIZING /
/ THESE SIX PARAMETERS MAY BE CHANGED TO SUIT YOUR NEEDS /
$upload = $_FILES[‘upload’][‘name’];
$o_path =“images/COMPANIES/”;
$s_path = “images/thumbs/”;
$file = $upload;
$save = $file;
$t_w = 200;
$t_h = 150;
/ DO NOT CHANGE THIS NEXT LINE */
Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path);
}else{
//Gives and error if its not
$error_message .= "Sorry, there was a problem uploading your file.";
}}
if (count($setArray) > 0) { // do we have at least on field to update?
$setstr = join (’, ', $setArray); // form a comma separated string of our updates
$query = “UPDATE companies SET $setstr WHERE id = $id”; // update it
echo $query;
mysql_query($query) or die(mysql_error());
}
header(“Location: view01.php?id=” . $id);
exit(0);
?>[/code]
Near the destination folder this line:
if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) {
Copies the image to the target folder but i already have a destination folder.
Which one is it that i have to get rid of (if this is the problem)…
If any of you guys could please help me, as im a bit stuck at the moment with this one. Stuck being brain dead as i have looked at it far too much now, and it’s turning into a blurrrrrr.
Thank you in advance, if you need any more info, let me know. Cheers.