...

View Full Version : w3c File Upload



groog
07-27-2007, 05:24 AM
Ok I read the post rafiki made and didn't understand it because I'm very new at php and I only know what I read on w3c from tutorial 1 to uploading files. I did read everything and I didn't just do a cheap copy and paste of this script.

http://groogstestpages.freehostia.com/upload.php
try uploading a gif or jpeg

first page

<html>
<head>
<title>
Upload Test
</title>
<link href="upload.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<form action="upload_file.php" method="POST" enctype="multipart/form-data">
<label for="file">File:</label>
<input type="file" name="file" id="file">
<input type="submit" name="submit" value="Upload">
</form>
</div>
</body>
</html>

Second Page

<html>
<head>
<title>
Upload Test Complete
</title>
<link href="upload.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<?php
if (($_FILES['file']['type'] == "image/gif")
|| ($_FILES['file']['type'] == "image/pjpeg"))
{
if ($_FILES['file']['error'] > 0){
echo "Error" . $_FILES['file']['error'] . "<br />";
}
else
{
echo "Name: " . $_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 />";
move_uploaded_file($_FILE['file']['tmp-name'], "uploads/" . $_FILES['file']['name']);
echo "stored in: " . "uploads/" . $_FILES['file']['name'];
}
}
else
{
echo "invalid file<br>";
var_dump($_FILES);
}
?>
</div>
</body>
</html>

I'm hoping you guys can see something here because the guys at php freaks couldn't figure it out (some php gurus they are!). I do have a folder set up named uploads in the same directory as this file so that's all set up.

thesavior
07-27-2007, 05:34 AM
I dont see anything wrong with your code either, I'm thinking it might have something to do with your server setup. I'm not sure whether you need to have safe mode disabled for $_FILE transactions. If your willing, make a file that is completely empty save for:



<?php
phpinfo();
?>


Save it, upload it, and link it here so we can see if it is something with your server.

From the way your code is acting, its failing here:

if (($_FILES['file']['type'] == "image/gif") || ($_FILES['file']['type'] == "image/pjpeg"))

thus making me check your form but that is correct. So I am clueless save for server error.

groog
07-27-2007, 05:47 AM
From the way your code is acting, its failing here:

if (($_FILES['file']['type'] == "image/gif") || ($_FILES['file']['type'] == "image/pjpeg"))


That's exactly what I thought. It makes sense.

Here's that page: http://groogstestpages.freehostia.com/phpinfo.php

NancyJ
07-27-2007, 08:18 AM
the problem is in your html not your php. Sometimes it pays to cut & paste - you typoed ;)

If the code you posted here is the same as you the code you posted to the other forum I'm not suprised they couldnt spot the problem. The form you have posted here is correct! But the form on your site has this: encypte="multipart/form-data"

groog
07-27-2007, 01:02 PM
I did make that change but I must not have uploaded the file. It does work now but the image doesn't appear to be uploading.

_Aerospace_Eng_
07-27-2007, 01:27 PM
You should look back at the thread you got the code from. Its been developed further and should now work. See if the changes made make yours work.
http://www.codingforums.com/showthread.php?t=119866



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum