0

Hello everybody

I made an personal form to upload files to different maps wich can be selected.
I'm making an mistake, but I don't know how to fix this. There is no error only when the file is processed, the file isn't kept in the directory map wich was selected.
It echoes: "There was an error uploading the file, please try again!Smile...

This is my form:

<form enctype="multipart/form-data" action="upload.php" method="post"> 
            <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> 
            Choose a file to upload: 
  <input name="uploadedfile" type="file" /> 
  <select name="uploads" size="1"> 
    <option>uploads</option> 
    <option>files</option> 
  uploads</select> 
  <br /> 
  <input type="submit" value="Upload File" /> 
          </form> 

And here is my upload script.

<?php 
$sTargetPath = 'c:/wamp/www/uploading/uploads/'.((isset($_POST['uploads']) && is_string($_POST['uploads']))? $_POST['uploads'].'/' : ''); 
if(is_dir($sTargetPath) && move_uploaded_file($_FILES['uploadedfile']['tmp_name'] 
     . basename($_FILES['uploadedfile']['tmp_name']), $sTargetPath)) { 

    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded"; 

} 
 else{ 
    echo "There was an error uploading the file, please try again!"; 
} 
echo "smile..."; 
?>  

Thanks for every help and feedback

Edited by Reverend Jim: Fixed formatting

2
Contributors
1
Reply
8
Views
7 Years
Discussion Span
Last Post by farhan386
0

$sTargetPath = 'c:/wamp/www/uploading/uploads/'

it is better and more convenient to use relative path instead of absolute path.

$sTargetPath = 'uploading/uploads/'

Windows use \ as separator, if you insist to use absolute path. Don't forget to add another one as escape character.

'c:\\wamp\\www\\uploading\\uploads\\'
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.