DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

Uploading files to local server

By: Sunil | 22 Sep 2008 2:14 pm

Hi all,

This is probably a noob question:

I am creating a site on my local computer only...not on a server, and I have an upload file part (<input type='file'> ), but I want to know if it is possible to still have the files go to a certain directory on my own computer.

In other words, to make sure its working right before it goes up on a real server, I test it and select a file in one directory, and when i submit it, that file automatically is copied and pasted (still in the original directory too, only a copy would be made) into the new directory.

Thanks,

Comments

Yes. You can do this just fine. The directory where your files will ultimately go must be writable by your webserver user. The details of this
depends on your configuration and operating system.
By: Shailesh Singh | 22 Sep 2008
There can be a large number if differences between your
local PC's config and the server config. Some of these can strongly affect
file system operations so please don't assume that something that works on
your local PC is going to work on the server.

There are two basic ways. One is to 'move' the uploded file from the
temporary directory in which case the file will retain the ownership of the
user session. The other is to stream it to the new directory and 'unlink' it
from the temporary directory. In this case the file will be owned by the
script authority. There can be many differences and you will have to set
file and folder permission's in accordance with these differences.
By: Manoj | 22 Sep 2008
My operating system is XP
In php.ini I looked at File_Uploads and changed the 'upload_tmp_ dir'
to the folder i want the files to go to, but still no success.

Any other changes that I have to make?
By: Admin | 22 Sep 2008

Have you created the phpinfo.php page yet?

<?php
phpinfo();
?>
save as phpinfo.php

Now you can see everything in your ini.

Look down at PHP Core and find the line file_uploads and make sure the value and

master are set to ON.

Next find the
upload_max_filesie, upload_temp_ dir and post what those say.

Next, make sure your form is created similar to this:


<!-- The data encoding type, enctype, MUST be specified as below -->

<form enctype="multipart/ form-data" action="__URL_ _" method="POST" >

<!-- MAX_FILE_SIZE must precede the file input field -->

<input type="hidden" name="MAX_FILE_ SIZE" value="30000" />

<!-- Name of input element determines name in $_FILES array -->

Send this file: <input name="userfile" type="file" />

<input type="submit" value="Send File" />

</form>


If it doesnt say enctype="multipart/ form-data" then you arent uploading anything.



By: Manoj | 22 Sep 2008
It still doesn't appear to work, I added those lines that I stupidly
forgot to include (the enctype... as well as the MAX_FILE_SIZE) .
File Uploads is set to On, so it should be working.

The temporary directory for the files might be the problem... I
changed it to "/tmp" because in one of my PHP books they put that.

I'm not exactly sure where this "/tmp" would be located though.
By: Manoj | 22 Sep 2008
please respond below instead of on top of responses.

In your php.ini you changed your upload_tmp_dir to where?

I dont know the default on windows but when I was on XP I set up my development
environment like this:

C:\development\
C:\development\ tmp

And then my normal working files were

C:\development\ clientname\

so my tmp was where I set it up to be.

Since this is your own computer you are working at then you can set it to be
anyplace.

Once you set this you have to restart apache before it reads the values in the
php.ini.
By: Shailesh Singh | 24 Sep 2008
When PHP is used to upload a file it is held in a temporary directory
which is specified in the php.ini file.

Once your file has been uploaded it is removed again unless you specify
in your script the directory where you want the file to be moved to.

The tmp directory is literally temporary.

If you are wanting to learn how to do this I highly recommend the
friends of ed book PHP Solutions by David Powers. It covers this
subject plus much more and is really easy to follow.

Hope this helps.
By: Shailesh Singh | 24 Sep 2008
I have to move the uploaded file from the temp folder to a
different folder then using PHP, right?

I tried copying a function from my book, but another problem arose:
there is supposed to be an automatic $_FILES superglobal, but this is
not the case for me. It gives me an error when I try to echo something
like $_FILES['upload' ]['name'] or such.

Once I get aorund this obstacle, I'll be able to try the new temp
folder stuff.

If you know why my $_FILES superglobal isn't working, please help.

Thank you very much
By: Sunil | 24 Sep 2008
An error for echo($_FILES[ 'upload'] ['name']) ; does not

necessarily mean that there is no $_FILES superglobal.



The above assumes that you are using a form with <input type="file"

NAME="upload" >



Try this



if(!is_set($ _FILES))

{

echo("There are no files uploaded\n") ;

die();

}

foreach($_FILES as $key => $thisfile)

{

echo("For the form input name that is [" . $key . "]\n\n");

echo("Remote file (name) is [" . $thisfile['name' ] . "]\n");

echo("Browsers suggested mime (type) is [" . $thisfile['type' ] . "]\n");

echo("Actual file (size) is [" . $thisfile['size' ] . "]\n");

echo("Server temporary name (tmp_name) is [" . $thisfile['tmp_ name'] .

"]\n");

echo("Upload (error) is [" . $thisfile['error' ] . "]\n\n\n\n") ;

}


By: Sunil | 24 Sep 2008

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move