This is a discussion on RE: [PHP] Moving Files/ Temporary Names within the PHP General forums, part of the PHP Programming Forums category; > > I am trying to crate the function that will allow the > administrator to Move a selected file ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
> > I am trying to crate the function that will allow the > administrator to Move a selected file to a different folder. > I have looked at move_uploaded_file () and it seems that > the source file to move needs to actually be the file's temp name. > If the file has recently been uploaded then the temp name is > accessible via $_Files[] array, but if the file was uploaded say a > week before I assume that the temp name is no longer there. Not only is the temp name no longer there, nor is the file! When you upload a file, the temporary place where PHP puts it is only valid for the life of the script which processes the file upload -- it is automatically deleted upon completion of that script. - This is how I understood it. If you want the file to go into a holding location until your administrator can approve it and move it to its real final location, then the holding location should be the target of the move_uploaded_file(). This makes it up to you to decide what you want the structure of your holding location to be, and how you want to keep track of any files currently populating it. - I'm a little confused. The files are already in there real location. It is just that someone may want to change that location at a later date. e.g. they upload an image to a folder and two months later decide it is better placed in a different folder. Or am I missing something really obvious. The other solution I can see is to copy the file to the new location and delete the original Cheers |
|
|||
|
caspar kennerdale wrote:
> - I'm a little confused. The files are already in there real location. It is > just that someone may want to change that location at a later date. > e.g. they upload an image to a folder and two months later decide it is > better placed in a different folder. > > Or am I missing something really obvious. > > The other solution I can see is to copy the file to the new location and > delete the original Check out rename(). That might be what you want. http://us3.php.net/rename Also, if you are on *nix (I don't remember if there is an equivalent in MS windows), you could use the mv command via the exec function. - Brad |
|
|||
|
On Monday, July 14, 2003, 11:04:48 PM, caspar wrote:
ck> If you want the file to go into a holding location until your administrator ck> can approve it and move it to its real final location, then the holding ck> location should be the target of the move_uploaded_file(). This makes it up ck> to you to decide what you want the structure of your holding location to be, ck> and how you want to keep track of any files currently populating it. ck> - I'm a little confused. The files are already in there real location. It is ck> just that someone may want to change that location at a later date. ck> e.g. they upload an image to a folder and two months later decide it is ck> better placed in a different folder. ck> Or am I missing something really obvious. Hrmm ... might be. Maybe you are making this more difficult than it is? Once the file is uploaded, move it to _a_ location, doesn't have to be its permanent location, just so its moved from the temp directory. Keep in mind that the directory that you move it to, PHP has to be able to access it (have proper permissions). Specifically, Apache (or your webserver), has to have proper permissions for the directory. In your application code ... you can implement a move() function that can either call the unix (mv) or windows (move) commands to move the file to another location (same permission restrictions apply). The thing about move is, its a copy + delete function in one, so you have to be careful about permissions. You might have permissions to copy, but not delete. Hoping this helps, -- Regards, Burhan Khalid phplist[at]meidomus[dot]com http://www.meidomus.com |
|
|||
|
In your application code ... you can implement a move() function that can either call the unix (mv) or windows (move) commands to move the file to another location (same permission restrictions apply). The thing about move is, its a copy + delete function in one, so you have to be careful about permissions. You might have permissions to copy, but not delete. -- If move is essentially a copy and delete- then this seems to be my best approach rather than using move_uploaded_file () as I do not have the tmp names. Want I want to do is to allow the user the option to upload a file, rename a file, delete a file and finally to move a file. move_uploaded_file() seems relevant at the time of uploading, but in my scenario this has happened long before and no the user wishes to change the permanant location of the file. Like any file/ directory handler. The final script could be on 'nix or windows so I want all funtions to be platform independent Cheers |