944,099 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2212
  • PHP RSS
Dec 19th, 2005
0

uploaded file origin directory

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
tristan17 is offline Offline
51 posts
since Sep 2005
Dec 20th, 2005
0

Re: uploaded file origin directory

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
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
RamiroS is offline Offline
57 posts
since Mar 2005
Dec 21st, 2005
0

Re: uploaded file origin directory

Quote 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
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
tristan17 is offline Offline
51 posts
since Sep 2005
Dec 21st, 2005
0

Re: uploaded file origin directory

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.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
RamiroS is offline Offline
57 posts
since Mar 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how to use gd
Next Thread in PHP Forum Timeline: Not able to change/update password





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC