ericburnard Posted January 10, 2008 Share Posted January 10, 2008 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 Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 10, 2008 Share Posted January 10, 2008 Is the folder writeable? Quote Link to comment Share on other sites More sharing options...
ericburnard Posted January 11, 2008 Author Share Posted January 11, 2008 Is the folder writeable? It is indead Quote Link to comment Share on other sites More sharing options...
adam291086 Posted January 11, 2008 Share Posted January 11, 2008 put error_reporting(E_ALL); At the top of the script and show me any errors Quote Link to comment Share on other sites More sharing options...
ericburnard Posted January 12, 2008 Author Share Posted January 12, 2008 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)) Quote Link to comment Share on other sites More sharing options...
br0ken Posted January 12, 2008 Share Posted January 12, 2008 $_FILES["file"]["type"] The word file here needs to refer to the name of your upload input element. So if in the form you had: <input type="Upload" name="fileToBeUploaded"> Then you would need: $_FILES["fileToBeUploaded"]["type"] Could you post your form code? Quote Link to comment Share on other sites More sharing options...
ericburnard Posted January 12, 2008 Author Share Posted January 12, 2008 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'); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.