uploaded file origin directory

Reply

Join Date: Sep 2005
Posts: 51
Reputation: tristan17 is an unknown quantity at this point 
Solved Threads: 1
tristan17 tristan17 is offline Offline
Junior Poster in Training

uploaded file origin directory

 
0
  #1
Dec 19th, 2005
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']['tmp_name']))
{
$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
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 48
Reputation: RamiroS is an unknown quantity at this point 
Solved Threads: 0
RamiroS's Avatar
RamiroS RamiroS is offline Offline
Light Poster

Re: uploaded file origin directory

 
0
  #2
Dec 20th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 51
Reputation: tristan17 is an unknown quantity at this point 
Solved Threads: 1
tristan17 tristan17 is offline Offline
Junior Poster in Training

Re: uploaded file origin directory

 
0
  #3
Dec 21st, 2005
Originally Posted by RamiroS
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 48
Reputation: RamiroS is an unknown quantity at this point 
Solved Threads: 0
RamiroS's Avatar
RamiroS RamiroS is offline Offline
Light Poster

Re: uploaded file origin directory

 
0
  #4
Dec 21st, 2005
Ok, the temporary filename (including path) is stored in the $_FILES['userfile']['tmp_name'] ... 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:

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

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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC