3 Replies - 401 Views - Last Post: 03 March 2011 - 08:50 AM Rate Topic: -----

#1 baxter111  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 77
  • Joined: 30-June 08

CMS - Saving File Location

Posted 03 March 2011 - 08:05 AM

Hello,

I am trying to store a new product into my database, I have managed to save the file onto my webserver using the move_uploaded_file but i am just wondering how i now find the new file location so i can store the directory into my database.

Here is the code i have at the moment:


<?php

    //Get Connection File

    include '../includes/connect.php';

    //Declare DB Name

    $tbl_name="product"; // Table name

    //Get New User Credentials From Form
    $new_p_name = $_POST['p_name'];
    $new_p_description = $_POST['p_description'];
    $new_p_bullet_1 = $_POST['p_bullet_1'];
    $new_p_bullet_2 = $_POST['p_bullet_2'];
    $new_p_bullet_3 = $_POST['p_bullet_3'];
    $new_p_bullet_4 = $_POST['p_bullet_4'];
    $new_p_bullet_5 = $_POST['p_bullet_5'];
    $new_p_bullet_6 = $_POST['p_bullet_6'];
    $new_p_price = $_POST['p_price'];
    $new_p_img = $_FILES['p_img']['name'];
    $type = $_FILES['p_img']['type'];
    $tmpname = $_FILES['p_img']['tmp_name'];
    $error = $_FILES['p_img']['error'];

    if ($error > 0)
       die("Error uploading file! Code'$error.");
     else
        move_uploaded_file($tmpname, "uploaded/".$new_p_img);
  
         
    //Connect To Database Table
    mysql_select_db("$db_name") or die ("Could not connect to DB");

    //Run Update Query
    $sql= "INSERT INTO $tbl_name (p_name, p_description, p_bullet_1, p_bullet_2, p_bullet_3, p_bullet_4, p_bullet_5, p_bullet_6, p_price) VALUES ('$new_p_name','$new_p_description','$new_p_bullet_1','$new_p_bullet_2','$new_p_bullet_3','$new_p_bullet_4','$new_p_bullet_5','$new_p_bullet_6','$new_p_price')" or die (mysql_error());
    $enterdate = mysql_query($sql) or die (mysql_error());

    echo "New Product Added"
?>




Basically i am trying to find the new file location so i can add this into the database.

Cheers,

Scott

Is This A Good Question/Topic? 0
  • +

Replies To: CMS - Saving File Location

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,238
  • Joined: 08-June 10

Re: CMS - Saving File Location

Posted 03 March 2011 - 08:09 AM

"uploaded/".$new_p_img ? that’s where I’d look first.

and before I forget, your code is susceptible to SQL Injection attacks.

This post has been edited by Dormilich: 03 March 2011 - 08:10 AM

Was This Post Helpful? 0
  • +
  • -

#3 baxter111  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 77
  • Joined: 30-June 08

Re: CMS - Saving File Location

Posted 03 March 2011 - 08:17 AM

THanks mate, yes i know - that will be changed.

I've looked there but can't seem to find it.
Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: CMS - Saving File Location

Posted 03 March 2011 - 08:50 AM

You should be able to use the following to get the full path to your moved file:
$full_path = realpath("uploaded/" . $new_p_img);

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1