Jump to content

can't get file to upload with PHP


Jago6060

Recommended Posts

I'm trying to get a newsletter uploaded onto a site I monitor.  My code has been working up until recently for some reason.  To my knowledge, nothing has been changed.  Now when I try to upload the file, I click upload and IE spins for a while, and then goes to the site homepage, which is supposed to happen.  But when I check the newletter page, nothing new comes up, and the file never gets uploaded to the proper folder.

 

heres my upload form code...(yes I know my select is mundane but I didn't feel like messing with an array)

<?
session_start();

if (isset($_SESSION[user])){
echo "
<h2>Upload a Newsletter</h2>
<form enctype=multipart/form-data action=upload_news.php method=POST>
<input type=hidden name=MAX_FILE_SIZE value=100000000 />
Choose a file to upload: <input name=uploadedfile type=file /><br />
Select the corresponding month:
<select name=month>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select><br>
Please select a day:
<select name=day>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<br>
<input type=submit value=Upload File />
</form>
";
}else{
header ('Location: index.php');
exit;
}
?>

 

and here is my upload process...

 

<?
if (!isset($_SESSION[user])){
    header ('Location: index.php');
}

session_start();
include 'connect.php';

$month = $_POST[month];
$day = $_POST[day];


// Where the file is going to be placed 
$target_path = "./uploads/news/";

/* Add the original filename to our target path.  
Result is "/uploads/news/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$_FILES['uploadedfile']['tmp_name'];  

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
    @mysql_select_db($database) or die( "Unable to select database");
    $sql = "INSERT INTO crc_news (news_dir,month,day)values('$target_path','$month','$day')";
    $result=mysql_query($sql);
    mysql_close();
    header ('Location: logout.php');
}else{
    echo "There was an error uploading the file, please try again!";
    echo "<a href=upload_news_form.php>Back</a>";
}
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/94822-cant-get-file-to-upload-with-php/
Share on other sites

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.