| | |
uploaded file origin directory
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2005
Posts: 51
Reputation:
Solved Threads: 1
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
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
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
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
•
•
Join Date: Sep 2005
Posts: 51
Reputation:
Solved Threads: 1
•
•
•
•
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
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['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.
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.
![]() |
Similar Threads
- uploaded file moving to new directory (PHP)
- File doesn't upload into the directory I specified. Need help! (PHP)
- Put file in protected directory? (Networking Hardware Configuration)
Other Threads in the PHP Forum
- Previous Thread: how to use gd
- Next Thread: Not able to change/update password
| Thread Tools | Search this Thread |
apache api array auto beginner binary broken cache cakephp checkbox class cms code codingproblem cron curl customizableitems database date display dynamic echo email error errorlog file files filter folder form format forms forum function functions gc_maxlifetime global google headmethod host href htaccess html image include insert ip javascript joomla limit link login mail malfunctioning memmory memory menu mlm multiple mysql nodes oop parameter parsing paypal pdf php phpmysql popup query radio random recursion recursiveloop remote script search select server sessions snippet source space sql static survey syntax system table trouble tutorial up-to-date update upload url validator variable video web youtube





