Jump to content

Upload problems


ericburnard

Recommended Posts

Ive just written my first upload script.

When i upload a picture it should be placed in the folder "images/uploads"

When the script is run it says the image was uploaded and the data is in the database but when i look in the folder the image is not there.

 

this is my code

 

<?php
include ('mheader.html');
include ('db.php');


if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
&& ($_FILES["file"]["size"] < 1000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
    
     $file = $_FILES["file"]["name"];  
    
    if (file_exists("images/uploads/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "images/uploads/" . $_FILES["file"]["name"]);
      echo "Stored in images/uploads/ <BR><BR><BR>";
      
        $con = mysql_connect("$host","$username","$password");
          if (!$con)
          {
          die('Could not connect: ' . mysql_error());
          }
        mysql_select_db("erikee10_eric", $con);$sql="INSERT INTO photos (file, pname, des, who, date)
VALUES
('$file','$_POST[pname]','$_POST[des]','$_POST[who]','$_POST[date]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
      }
    }
  }
else
  {
  echo "Invalid file";
  }
  
  

?>

 

sorry if its a bit messy :s

 

Eric

Link to comment
https://forums.phpfreaks.com/topic/85440-upload-problems/
Share on other sites

put

 

error_reporting(E_ALL);

At the top of the script and show me any errors

 

This is the error i get -

Notice: Undefined index: file in /home/www/ericburnard.freehostia.com/upload2.php on line 7

Notice: Undefined index: file in /home/www/ericburnard.freehostia.com/upload2.php on line 8

Notice: Undefined index: file in /home/www/ericburnard.freehostia.com/upload2.php on line 9

 

the script on those lines is -

7   if (($_FILES["file"]["type"] == "image/gif")
8   || ($_FILES["file"]["type"] == "image/jpeg")
9   || ($_FILES["file"]["type"] == "image/pjpeg")
10  && ($_FILES["file"]["size"] < 1000000))

Link to comment
https://forums.phpfreaks.com/topic/85440-upload-problems/#findComment-437264
Share on other sites

This is the form page

 

<?
include ('mheader.html');
include ('db.php');

echo '




<div id="f1">	<form action="upload2.php" method="post" enctype="multipart/form-data" class="f1">

<table border="0pt">
<tr>
  <td>
   <label for="file">
    Filename:
   </label> 
  </td>
  <td><input type="file" name="file" id="file" class="texta"/> 
  </td>
</tr>
  <tr>
  <td>Photo Name: 
  </td>
  <td><input type="text" name="pname" class="texta">
  </td>
</tr>
  <tr>
  <td>Description: 
  </td>
  <td><input type="text" name="des" class="texta">
  </td>
</tr>
  <tr>
  <td>Whos In It: 
  </td>
  <td><input type="text" name="who" class="texta">
  </td>
</tr>
<tr>
  <td>
  </td>
  <td>
   <input type="submit" value="Submit" class="texta">
  </td>
</tr>
</table>
</form> 
</div>';

include ('footer.html');

?>

Link to comment
https://forums.phpfreaks.com/topic/85440-upload-problems/#findComment-437284
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.