View Full Version : filename from upload

04-03-2004, 02:16 PM
i need to know how to get C:\Documents and Settings\.....\image.jpg to just be image.jpg when i upload an image... because i want the filename to be added to my database. but since the upload isnt always from C:\Documents and Settings\... it could be from M:\Pics\... and i need to remove all those first parts of the uploaded filename thing. any way to do that?

Mr J
04-03-2004, 03:48 PM
Please try the following




04-03-2004, 06:06 PM
that doesnt help me... just fills my page with javascript errors.... is there a way to do it in php?

Mr J
04-03-2004, 06:19 PM
Did you change formname and elementname to the values that you are using?

and integrate it in your script

04-03-2004, 06:26 PM
so u mean like
full_path=document.form1.file.<?php echo $_POST['file']; ?>
this doesnt work... it says that that path is null or doesnt exist

Mr J
04-03-2004, 06:36 PM
Sorry but I don't know about PHP

This works for javascript, I've referenced a couple of divs so you can see

<script language="javascript">
function upload(){

document.getElementById("temp1").innerHTML="Full path = "+full_path
document.getElementById("temp2").innerHTML="Short path = "+short_path
// -->

<form name="f1" ENCTYPE="multipart/form-data" >
<INPUT type="file" name="image_file">
<INPUT type="button" value="Apply" onclick="upload()">

<div id="temp1"></div>
<div id="temp2"></div>

This is what I get

Full path = C:\WINDOWS\Desktop\matrix.htm
Short path = matrix.htm

04-03-2004, 06:53 PM
When you upload using php, you don't get any info about the users file directory. The file they upload will be stored in your tmp directory as 1245TMP or similar. The only thing you'll recieve is the filename itself. So I don't understand your problem at all

04-03-2004, 07:29 PM
so if i did....

$con = mysql_connect("localhost","user","pass");
$filename = "<script>

$sql = "INSERT INTO `files` (`filename`) VALUE ('$filename')";
this will add the short filename into the db? i have the php upload code above this code and it works great. but in my php script that pulls results from the database, it checks the filename and finds the file in the directory it uploads to.

04-03-2004, 07:39 PM
To get a file name, use $_FILES['uploadfieldname']['name']. You don't need javascript, plus that wont work.

04-03-2004, 08:03 PM
but doesnt $_FILES['uploadfieldname']['name'] give you the C:\Documents......... ? i dont want that in the database because then it will be looking for the directory C:\.... and then everything won't work

04-03-2004, 08:13 PM
It just gets the name of the file:


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum