hi i wan to add my .xml files into database and into the directory uploads . i have following done into the php

            if(isset( $_FILES["f_name"])
            {
            $path = "";
            if(file_exists("uploads/" . $_FILES["f_name"]["name"]))
            {
                echo $_FILES["f_name"]["name"] . " already exists. ";
            }
            else if($_FILES["f_name"]["type"]!= "text/xml")
            {
                echo "invalid type is tried to upload.";
            }
            else 
            {
            move_uploaded_file($_FILES["f_name"]["tmp_name"],  "uploads/" . $_FILES["f_name"]["name"]);
            $fileName =  $_FILES["f_name"]["name"];
            $path = "uploads/" . $_FILES["f_name"]["name"];         
            }
            mysql_query("INSERT INTO mytable VALUES(NULL,'$path',) or die(mysql_error());
            }

and here is my form in html

<form action="xyz.php" method="post" name="mar"  enctype="multipart/form-data">
<input type="file" placeholder="Feed Upload*" required="required" name="f_name" class="inp-form file_1"  />
<input type="submit" value="" name="submit" class="form-submit" />
</form>

now my question is that my query execute accurately but it doesn't insert the path of the file. now i want to store the path of the file which is in the current directory so that whenever i need the file i just single click on to the given path and the file will be executed??
is there any mean to store the path of the file and then execute that file? or i have to store a complete file into database??

Try this correction to your code (not sure what the NULL is for in your query and so have removed, I have also guessed at the field name in your table):

$fileName =  $_FILES["f_name"]["name"];
            $path = "uploads/" . $filename;         
            }
            mysql_query("INSERT INTO mytable file_path VALUES ('".$path."')") or die(mysql_error());

thnx for reply simplypixie NULL is the id of in the table for indexing which is auto increment. and what i want to upload a file into the directory named uploads folder. and for execution i want to add the root path of that file into the db. so that whenver whenever i want to execute that file i just make a simple click and the file executed.

Member Avatar for diafol

I'd advise not storing any paths in the DB. IMO, better to store the path in a constant - that way if you decide to rename the folder or move the folder, you don't have to mess with update queries - which could be really messy. Constants are global, even within functions and classes, so you don't have to worry about them being out of scope.

e.g.

define("UPLOAD_DIR", "/uploads/");

$filepathname = UPLOAD_DIR . $row['filename'];
$label = $row['filelabel'];
...

echo "<a href='$filepathname'>$label</a>";

shahai.ali - I presumed that was what it is for and if it is set to auto-increment you don't need to include any reference to it in your insert query, the database will automatically add the id for you. Have you actully tried the new code??

diafol - indeed, good advice!

i have done it with the following amendments into the code.

echo realpath($path);

this give me the absolute path of the file..thnx all for replies

hey please help me actually i have used the command as part of program
<?php echo "<a href= echo '$Geneprocess'>$Geneprocess</a>";?>
getting a hyperlink bt when i am clicking over it it gives an error for all the hyperlink.... the error is

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404

localhost
Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7

so please tell me where am i getting wrong????????

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.