php script for uploading files to a remote server
I'm am completely new to PHP scripting so these questions I have are
probably going to be silly simplistic ones, so please forgive me.
Right now I have code that I'm wanting to use to send files to set folder
in my server.
My code looks like this:
<?
$_SESSION['directory'] = $_POST['directory'];
$uploaddir = './'.$_GET["dir"];
$file = basename($_FILES['file']['name']);
$uploadfile = $uploaddir . $file;
print_r($_FILES);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
echo "http://ipaddress/images/{$file}/";
}
else
{
echo "Didn't Work!!!!";
}
?>
My URL call for this in my code looks like this:
http://server.foo.com/folder/uploadToDirectory.php?dir=selected_folder
However when I run my code, the file only gets sent to the root of the
directory like it would if I make this call:
http://server.foo.com/folder/uploadToDirectory.php
Can anyone see the reason as to why that is happening?
Following that if I want to save a file in a directory I need a separate
script from that if I want to upload it to the root of my server. How
would I go combing my two scripts into one, and what calls would I need to
make if I'm already using them like I've shown.
My other script looks like this:
<?
$file = basename($_FILES['file']['name']);
$uploadfile = $uploaddir . $file;
print_r($_FILES);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
echo "http://ipaddress/images/{$file}/";
}
else
{
echo "Didn't Work!!!!";
}
?>
Please note, I know this is a horrible way of doing things. I know that.
But this is code that only I am going to be using. No end client will see
this. So please, if you could help with the code I have provided I would
be truly grateful.
No comments:
Post a Comment