Jump to content


Photo

File Uploading Problems


  • Please log in to reply
3 replies to this topic

#1 fixafone123

fixafone123
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 05 June 2006 - 04:33 PM

First off, I am very much a novice when it comes to PHP so talk to me like I am an idiot [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

I have a script that uploads a file to my webserver and places a link to it in the database (MySQL)
It stopped working recently and if I remember correctly nothing has changed on my webserver

php-4.3.9-3.9.i386
mysql-4.1.12-3
httpd-2.0.52-22

Here is the script:

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]if(!empty($_FILES["userfile"])) {
$uploaddir = "/home/www/fisher/docs/seminarphp/admin/photos/"; // set this to wherever
//copy the file to some permanent location
if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploaddir . $_FILES["userfile"]["name"])) {

echo("file uploaded");
} else {
echo ("error!");
}
}
$picturename = $_FILES["userfile"]["name"];
mysql_query("UPDATE reserve SET picture='http://www.mywebserver.com/seminarphp/admin/photos/$picturename' WHERE uid='$rvar_choose'");[!--colorc--][/span][!--/colorc--]

I don't see "File Uploaded" or "error"...

Any help would be appreciated.
Thanks,
Kyle

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 05 June 2006 - 11:52 PM

Post your form ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 fixafone123

fixafone123
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 06 June 2006 - 02:56 PM

Here is the form that gets filled out to add a new Speaker to our Seminar database:

<html>
<head>
<title>Genetics Seminar - Add Speaker</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
<form action="speaker_insert.php" method="post" enctype="multipart/form-data" name="MForm">
  <p align="center">Use this form to book a Seminar Speaker<br>
    If you need to start a new semester, <a href="newsemester.php">Click Here </a></p>
  <table width="95%" border="0" align="center" cellpadding="2" cellspacing="0">
    <tr>
      <td colspan="4"> </td>
    </tr>
    <tr>
      <td width="25%">Speaker</td>
      <td width="1%"> </td>
      <td width="35%" valign="top"><input name="speaker" type="text" id="speaker" size="60"></td>
      <td width="34%" rowspan="6" align="center" valign="middle"><input type="submit" name="Submit" value="Submit"></td>
    </tr>
    <tr>
      <td>Speaker's Location </td>
      <td> </td>
      <td valign="top"><input name="location" type="text" id="location" size="60"></td>
    </tr>
    <tr>
      <td>Topic</td>
      <td> </td>
      <td valign="top"><input name="topic" type="text" id="topic" size="60"></td>
    </tr>
    <tr>
      <td>Host</td>
      <td> </td>
      <td valign="top"><input name="spkhost" type="text" id="spkhost" size="60"></td>
    </tr>
    <tr>
      <td>Time<font size="2"> </font></td>
      <td> </td>
      <td valign="top"><select name="spktime" id="select">
        <option value="12:00am">12:00am</option>
        <option value="12:30am">12:30am</option>
        <option value="1:00am">1:00am</option>
        <option value="1:30am">1:30am</option>
        <option value="2:00am">2:00am</option>
        <option value="2:30am">2:30am</option>
        <option value="3:00am">3:00am</option>
        <option value="3:30am">3:30am</option>
        <option value="4:00am">4:00am</option>
        <option value="4:30am">4:30am</option>
        <option value="5:00am">5:00am</option>
        <option value="5:30am">5:30am</option>
        <option value="6:00am">6:00am</option>
        <option value="6:30am">6:30am</option>
        <option value="7:00am">7:00am</option>
        <option value="7:30am">7:30am</option>
        <option value="8:00am">8:00am</option>
        <option value="8:30am">8:30am</option>
        <option value="9:00am">9:00am</option>
        <option value="9:30am">9:30am</option>
        <option value="10:00am">10:00am</option>
        <option value="10:30am">10:30am</option>
        <option value="11:00am">11:00am</option>
        <option value="11:30am">11:30am</option>
        <option value="12:00pm" selected>12:00pm</option>
        <option value="12:30pm">12:30pm</option>
        <option value="1:00pm">1:00pm</option>
        <option value="1:30pm">1:30pm</option>
        <option value="2:00pm">2:00pm</option>
        <option value="2:30pm">2:30pm</option>
        <option value="3:00pm">3:00pm</option>
        <option value="3:30pm">3:30pm</option>
        <option value="4:00pm">4:00pm</option>
        <option value="4:30pm">4:30pm</option>
        <option value="5:00pm">5:00pm</option>
        <option value="5:30pm">5:30pm</option>
        <option value="6:00pm">6:00pm</option>
        <option value="6:30pm">6:30pm</option>
        <option value="7:00pm">7:00pm</option>
        <option value="7:30pm">7:30pm</option>
        <option value="8:00pm">8:00pm</option>
        <option value="8:30pm">8:30pm</option>
        <option value="9:00pm">9:00pm</option>
        <option value="9:30pm">9:30pm</option>
        <option value="10:00pm">10:00pm</option>
        <option value="10:30pm">10:30pm</option>
        <option value="11:00pm">11:00pm</option>
        <option value="11:30pm">11:30pm</option>
      </select></td>
    </tr>
    <tr>
      <td>Location of Seminar <font size="2"> </font></td>
      <td> </td>
      <td valign="top"><input name="where" type="text" id="where" value="Department of Genetics Library - McDonnell Science Building" size="60"></td>
    </tr>
    <tr>
      <td>Speaker's Photo</td>
      <td><br></td>
          <td><input type=file name="userfile"></td>
          <td> </td>
          <td> </td>
    </tr>
    <tr>
      <td colspan="4">
          </td>
    </tr>
  </table>
          <?PHP
include "../conf/conf.php";
$data=mysql_query("select * from reserve") or die($SELECT_ERROR);
?>
 
 
<TABLE ALIGN="CENTER" BORDER="1" BORDERCOLOR="#990000">
<TR>
        <TD align="center"><B>ID<br>EDIT</B></TD>
        <TD align="center"><B>Date</B></TD>
        <TD align="center"><B>Speaker</B></TD>
        <TD align="center"><B>Topic</B></TD>
        <TD align="center"><B>Host</B></TD>
</TR>
 
<?PHP
$i=1;
while ($break_data=mysql_fetch_array($data))
{
   if ($i % 2)
  {
    $color = $tbl_oncolor;
  }
}
  else
  {
    $color = $tbl_offbgcolor;
  }
 
  $uid=$break_data['uid'];
  $dbdate=$break_data['dbdate'];
  $speaker=$break_data['speaker'];
  $location=$break_data['location'];
  $topic=$break_data['topic'];
  $spkhost=$break_data['spkhost'];
 
  print "<TR>";
  print "<TD BGCOLOR=$color>$uid <input name=\"choose\" type=\"radio\" value=\"$uid\"> </TD>";
  print "<TD BGCOLOR=$color>$dbdate</TD>";
  print "<TD BGCOLOR=$color >$speaker - $location</TD>";
  print "<TD BGCOLOR=$color>$topic</TD>";
  print "<TD BGCOLOR=$color>$spkhost</TD>";
  print "</TR>";
  $i++;
}
?>
</TABLE>
</form>
</body>
</html>


Here is the script the form gets sent to:

<?php
 
include "../conf/conf.php";
import_request_variables("gP", "rvar_");
 
mysql_query("UPDATE reserve SET speaker='$rvar_speaker', location='$rvar_location', topic='$rvar_topic', spkhost='$rvar_spkhost', spktime='$rvar_spktime', whereheld='$rvar_where' WHERE uid='$rvar_choose'");
 
$data=mysql_query("select * from reserve where uid='$rvar_choose'") or die($SELECT_ERROR);
?>
<style type="text/css">
<!--
.style1 {
        font-family: Arial, Helvetica, sans-serif;
        font-weight: bold;
}
-->
</style>
 
<P><center class="style1">Here is the entry you Added/Changed <BR>Please click <a href="newspeaker.php">Here</a> to return to the Add/Change page</center>
</P>
 
<TABLE ALIGN="CENTER" BORDER="1" BORDERCOLOR="#990000">
<TR>
        <TD align="center"><B>ID</B></TD>
        <TD align="center"><B>Date</B></TD>
        <TD align="center"><B>Speaker</B></TD>
        <TD align="center"><B>Topic</B></TD>
        <TD align="center"><B>Host</B></TD>
</TR>
 
<?PHP
$i=1;
while ($break_data=mysql_fetch_array($data))
{
   if ($i % 2)
  {
    $color = $tbl_oncolor;
  }
  else
  {
    $color = $tbl_offbgcolor;
  }
 
  $uid=$break_data['uid'];
  $dbdate=$break_data['dbdate'];
  $speaker=$break_data['speaker'];
  $location=$break_data['location'];
  $topic=$break_data['topic'];
  $spkhost=$break_data['spkhost'];
 
  print "<TR>";
  print "<TD BGCOLOR=$color>$uid</TD>";
  print "<TD BGCOLOR=$color>$dbdate</TD>";
  print "<TD BGCOLOR=$color >$speaker - $location</TD>";
  print "<TD BGCOLOR=$color>$topic</TD>";
  print "<TD BGCOLOR=$color>$spkhost</TD>";
  print "</TR>";
  $i++;
}
 
 if(!empty($_FILES["userfile"])) {
    $uploaddir = "/home/www/fisher/docs/seminarphp/admin/photos/"; // set this to wherever
    //copy the file to some permanent location
    if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploaddir . $_FILES["userfile"]["name"])) {
 
            echo("file uploaded");
} else {
        echo ("error!");
    }
}
$picturename = $_FILES["userfile"]["name"];
mysql_query("UPDATE reserve SET picture='http://www.genetics.wustl.edu/seminarphp/admin/photos/$picturename' WHERE uid='$rvar_choose'");

?>
</TABLE>


#4 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 06 June 2006 - 04:20 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] <!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />[/quote]

I am not sure if it makes a difference, but you should process the upload before output to the browser.

There is also a function is_uploaded_file()

It will return true if a the file was uploaded
Everything you want to know is here.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users