Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with setting destination of uploaded file dynamically

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
I have a basic PHP script that I use to upload files. I can hard code the destination in the PHP script, but I want to set it dynamically via a variable I issue via curl.

Here's the script I am working on:

<?php
$target_path = "$destination";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>

Here is the curl command:

curl -F "destination=/tmp" -F "uploadedfile=@file.txt"
Any assistance would be greatly appreciated!

Thanks,

John
 
I'm all set now. I figured it out.

<?php
if(isset($_POST['destination'])) $target_path= $_POST['destination'];
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>

curl -F "destination=/tmp" -F "uploadedfile=@file.txt"
 
i would add some strong security in there to stop people being able to upload trojans and other malicious code.
 
Hi jpadie,

Thank you for your feedback. It's behind Apache authentication and is internal only, so I think I should be all set.

Thanks,

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top