Jump to content

file upload not working...tried everything i can think of


trandrus

Recommended Posts

Have code to upload a file to a dir and nothing happens. No errors, the file simply doesn't upload. The path is correct, the dir is chmod 777, the file is less than maxfilesize. no matter what i do it always says "file was not moved":

 

<?php

error_reporting(E_ALL);

if ($HTTP_POST_VARS) {

foreach ($HTTP_POST_VARS as $field) {

	if (!$field) {

		echo "empty";

	}	
}
}

if ($_FILES) {

$target_path = "/uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

echo $target_path;

echo $_FILES['uploadedfile']['name'];

if (move_uploaded_file($_FILES['uploadedfile']['name'], $target_path)) {

	echo "file was moved to ".$target_path;

}else {
	echo "file was not moved";
}
} 

?>


<form enctype="multipart/form-data" action="application.php" method="POST">

              <table width="526" border="0" cellspacing="0" cellpadding="0">
                <tr> 
                  <td bgcolor="#F5F5F5" class="textreg"><br>
                    <span class="textbold"> Applicant Personal Information</span>: 
                    <br>
                    <br> 
                    <table width="526" border="0" cellspacing="0" cellpadding="1">
                      <tr> 
                        <td width="197" align="right" class="textreg">First Name: </td>
                        <td width="325" class="textreg"><input type="text" name="firstname" size="27" /></td>
                      </tr>
                      <tr> 
                        <td align="right" valign="top" class="textreg">Last Name: </td>
                        <td class="textreg"><input type="text" name="lastname" size="27" /></td>
                      </tr>
                      <tr> 
                        <td align="right" valign="top" class="textreg">Address:  
                        </td>
                        <td class="textreg"><input type="text" name="address" size="27" /></td>
                      </tr>
                      <tr> 
                        <td align="right" valign="top" class="textreg">City, State, 
                          Zip Code: </td>
                        <td class="textreg"><input type="text" name="citystatezip" size="27" /></td>
                      </tr>
                      <tr> 
                        <td align="right" valign="top" class="textreg">Phone: </td>
                        <td class="textreg"><input type="text" name="phone" size="27" /></td>
                      </tr>
                      <tr> 
                        <td align="right" valign="top" class="textreg">Position 
                          Title Description:  </td>
                        <td class="textreg"><select name="position" size="1" >
                              <option>Select Position</option>
                              <option>Senior Project Manager</option>
                              <option>Assistant Field Engineer</option>
                            </select></td>
                      </tr>
                      <tr> 
                        <td align="right" valign="top" class="textreg">Email:  
                        </td>
                        <td class="textreg"><input type="text" name="email" size="27" /></td>
                      </tr>
                      <tr>
                        <td align="right" valign="top" class="textreg">Comments: 
                        </td>
                          <td class="textreg"><textarea name="comments" id="comments"></textarea></td>
                      </tr>
                    </table>
                    <span class="textreg"><br>
                    </span> <table width="526" border="0" cellspacing="0" cellpadding="1">
                      <tr> 
                        <td width="10"> </td>
                          <td class="textreg">After completing all of the fields 
                            above, attach a copy of your resume. You can do this 
                            by selecting 'Choose' and locating the file on your 
                            computer. Select 'Send' when finished. Word and Acrobat 
                            PDF files are the preferred formats.<br>
                          <br><center>
					<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
                          <input name="uploadedfile" type="file" value="Browse"/> <input type="submit" value="Send" />
                          </center>
                          <br> </td>
                        <td width="15"> </td>
                      </tr>
                    </table>
                    <br> </td>
                </tr>
              </table> </form>

I just found your problem (other than the leading slash). Its a little late here and I'm tired.

 

if (move_uploaded_file($_FILES['uploadedfile']['name'], $target_path))

 

Should be

 

if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))

you can't move the file name. it's just a name it doesn't exist. The file you move is the temp file php creates

 

if (move_uploaded_file($_FILES['uploadedfile']['name'], $target_path)) {

 

Should be

if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

 

Ray

 

EDIT: LOL there must be an echo in here :)

try this code friend it will make a difference..

 

 

<?php

error_reporting(E_ALL);

if ($HTTP_POST_VARS) {

foreach ($HTTP_POST_VARS as $field) {

	if (!$field) {

		echo "empty";

	}	
}
}

if ($_FILES) {

$PATH = dirname(__file__);	
$target_path = "\uploads\\";	
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);	
$fullPath =  $PATH.$target_path;	
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$fullPath)) 
	echo "file was moved to ".$target_path;	
else 
	echo "file was not moved";
} 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.