Hi,

I had written a small program in php, which will allow a user to upload an image to the database. My question is whether can i locate the directory of the image from where it was uploaded from?


this is part of the code for uploading:

"
// Do this process if user has browse the
// file and click the submit button
if ($_FILES)
{
$image_types = Array (
"image/bmp",
"image/jpeg",
"image/pjpeg",
"image/gif",
"image/x-png",
"application/octet-stream");

if (is_uploaded_file ($_FILES))
{
$userfile = addslashes (fread
(fopen ($_FILES["userfile"]["tmp_name"], "r"),
filesize ($_FILES["userfile"]["tmp_name"])));
$file_name = $_FILES["userfile"]["name"];
$file_size = $_FILES["userfile"]["size"];
$file_type = $_FILES["userfile"]["type"];

"

any help will be greatly appreciated!

tristan

Sorry, I don't understand the question... so...

If you mean the directory from the source machine... as far as I know... you can't.

If you mean the directory where the image was uploaded it is ussualy the tmp folder. http://www.php.net/features.file-upload

Hi,

thanks for your reply, maybe i should make myself clearer. I want to know where will the uploaded files be stored? and is it possible that i can change the directory where the uploaded files will be stored?

rgds,
tristan

Ok, the temporary filename (including path) is stored in the $_FILES ... if you print that var you will see exactly where the file is and what is the name (a temporary one) that PHP assigned to it.

Always remember to move tha file to the place where you want the file to be, with a better name. For that use this:

$tmp_name = $_FILES['userfile']['tmp_name'];
$new_name = "/home/www/whatever/whatever/filename.xxx";
move_uploaded_file($tmp_name, $new_name);

As far as I remember you can change the place where temporary files are uploaded in your php.ini file, but keep in mind that sessions are stored there also and it is recommended to be your tmp folder.

If you want to change this folder to the one where you want your files to be when they are directly uploaded... don't do that. It's better to upload to the temp folder and then move it to the one you want.

This article has been dead for over six months. Start a new discussion instead.