/    Sign up×
Community /Pin to ProfileBookmark

inserting absolute path into mysql using php

Hi all

In one of my forms i have a html file object <input type=”file ……>. This ofcourse gives a text box and a browse button to locate the file from the local drive. I would like to insert this whole path that is dislayed in the textbox after the browse action is performed into a field in MySQL. But by default only the filename gets inserted into the database. How can the whole path be preserved?

Eg
I want to insert something like “C:DocumentMyFoldersubFolderimage.jpg” into a field in mySQL

But what is getting inserted is just “image.jpg”

How can I achieve this in php?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@roscorDec 15.2007 — what upload setup are you using, I have tried and successfully used this thread as posted by Bokeh [URL]http://www.webdeveloper.com/forum/showthread.php?t=101466[/URL]

I the inset the whole path into my database and when I call I use

[code=php]
//then from SELECT
$photo_id=$row['photo_id'];

//use string replace from C:DocumentMyFoldersubFolderimage.jpg leaving just image.jpg
$photo = str_replace("C:DocumentMyFoldersubFolder", "", $photo_id);

<img src="<? echo $photo; ?>
[/code]
Copy linkTweet thisAlerts:
@prachuauthorDec 15.2007 — Thanks for your reply roscor. But I do not want to upload images. All i want to do is store the whole path of the image file in the database. How do I do this?
Copy linkTweet thisAlerts:
@holidayDec 15.2007 — try using the add slashes function [code=php]addslashes('C:DocumentMyFoldersubFolderimage.jpg')[/code]
Copy linkTweet thisAlerts:
@prachuauthorDec 16.2007 — Sorry guys, I dont think I am putting my question correctly. I have html "file" control in my form.
[CODE]
<label>Archive file </label><input type="file" name="archiveFile" align="left"><br/>
[/CODE]

In the form, I am using the Browse button to locate the image file (image.jpg).

To get the value of this textbox that holds the path of the file, I say $_REQUEST['archiveFile'] after the form is submitted.

When I try to echo $_REQUEST[myFile'], what i get is just image.jpg. But what I want is the whole path of the file C:blahblahimage.jpg

Maybe the file control itself only gives the filename ?? In such a case how can i get the whole path? I guess this should be pretty simple. But I am just starting to learn Php.
Copy linkTweet thisAlerts:
@holidayDec 17.2007 — don't use $_REQUEST for files (and I wouldn't use it at all!). Use $_FILES
Copy linkTweet thisAlerts:
@prachuauthorDec 17.2007 — Thanks! But why shouldn't one use $_REQUEST. Isn't it just like reading the contents of any other control say a textbox? What is the difference between $_REQUEST and $_FILES?
Copy linkTweet thisAlerts:
@holidayDec 18.2007 — if I wanted to get POST data from a form, I would use "$_POST". If I wanted to get GET/URL data from a form I would use "$_GET". And if I wanted to get info from a cookie I would use "$_COOKIE". And if I wanted to get a file from a form I would use "$_FILES". You don't have to, it just makes things neater, and prevents conflicts like two things with the same name. It also takes away the little security provided by using POST.
×

Success!

Help @prachu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...