• We've upgraded our forums. Please post any issues/requests in this thread.

website upload

binsky3333

New Member
Joined
Jul 5, 2007
Messages
643 (0.17/day)
Likes
21
System Name Green Machine
Processor Intel e6420@ 2.13GHz
Motherboard ASUS p5n32-e -sli
Cooling 4x80mm fans
Memory 4gb G skill ddr2-800
Video Card(s) 2 EVGA Geforce 8800GTS 320MB
Storage 1 Western digital 500gb sata
Display(s) Dell e207wfp
Case Apevia x-cruiser green
Audio Device(s) X-fi Xtreme gamer
Power Supply BFG 800watt
Software Windows vista ultimate 64bit
#1
Hi,
I am trying to make a website upload page, but i cant.
Here is my Form:

<html>
<body><form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form></body>
</html>


And here is my upload.php:

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
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 />"; if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>


Basically im using http://w3schools.com/php/php_file_upload.asp
But whenever i try and upload something i get "invalid file"
BTW I AM USING XAMPP FOR TESTING!
Can anyone figure out whats wrong?
 

W1zzard

Administrator
Staff member
Joined
May 14, 2004
Messages
17,060 (3.44/day)
Likes
17,965
Processor Core i7-4790K
Memory 16 GB
Video Card(s) GTX 1080
Display(s) 30" 2560x1600 + 19" 1280x1024
Software Windows 7
#2
var_dump($_FILES);
to see whats the input data you get fed
 

binsky3333

New Member
Joined
Jul 5, 2007
Messages
643 (0.17/day)
Likes
21
System Name Green Machine
Processor Intel e6420@ 2.13GHz
Motherboard ASUS p5n32-e -sli
Cooling 4x80mm fans
Memory 4gb G skill ddr2-800
Video Card(s) 2 EVGA Geforce 8800GTS 320MB
Storage 1 Western digital 500gb sata
Display(s) Dell e207wfp
Case Apevia x-cruiser green
Audio Device(s) X-fi Xtreme gamer
Power Supply BFG 800watt
Software Windows vista ultimate 64bit
#3
I am not good with php! So what do you mean by that?
 
Joined
Aug 10, 2007
Messages
4,059 (1.07/day)
Likes
1,123
Location
Geneva, FL, USA
Processor Intel i5-6600
Motherboard ASRock H170M-ITX
Cooling Cooler Master Geminii S524
Memory G.Skill DDR4-2133 16GB (8GB x 2)
Video Card(s) Gigabyte R9-380X 4GB
Storage Samsung 950 EVO 250GB (mSATA)
Display(s) LG 29UM69G-B 2560x1080 IPS
Case Lian Li PC-Q25
Audio Device(s) Realtek ALC892
Power Supply Seasonic SS-460FL2
Mouse Logitech G700s
Keyboard Logitech G110
Software Windows 10 Pro
#4
echo "Invalid file"; is going to happen if the file is not a gif or jpeg, or if it's over 20KB.

Putting var_dump($_FILES); at the start of the script (after the opening <?php tag) shows you the content of the $_FILES array, and thus the file type and size of the file you're trying to upload.
 
Joined
Jul 5, 2007
Messages
643 (0.17/day)
Likes
21
System Name Green Machine
Processor Intel e6420@ 2.13GHz
Motherboard ASUS p5n32-e -sli
Cooling 4x80mm fans
Memory 4gb G skill ddr2-800
Video Card(s) 2 EVGA Geforce 8800GTS 320MB
Storage 1 Western digital 500gb sata
Display(s) Dell e207wfp
Case Apevia x-cruiser green
Audio Device(s) X-fi Xtreme gamer
Power Supply BFG 800watt
Software Windows vista ultimate 64bit
#5
oh ok, thanks!