Problems with uploading image to server

Hi,

I’m trying to load image using $_FILES[‘file’][‘name’], but it doesn’t seem to work.
It looks like the submit form works ok. But the php file doesn’t get the details of the file.
I think $_FILES is empty… is this possible?

I took some help with this website:

And this is my web page:
http://partymagnets.ca/freeMagnetSample.html

What am I missing here? or what am I doing wrong…

I’ll appreciate any help you can give me!
Thank you very much !
Ronen

post your php script here

ok.

This is what I get after clicking submit:

You’ve got a message for FREE sample of Partymagnets.ca

Full name: asda
Address: dasjkd
City: jkdaksndkn
PostalCode: dnas,d
Caption on Magnet: dsa,d
Phone number: 123
Email Address: [email protected]
Path: uploads/


And this is the uploadFile.php file code:
[php]

<?php $submit = $_POST['submit']; $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['file']['name']); if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['file']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } echo $target_path . "
"; if($submit) { $name = $_POST['fullname']; $address = $_POST['address']; $postalcode = $_POST['postalcode']; $city = $_POST['city']; $caption = $_POST['caption']; $phone = $_POST['phone']; $email = $_POST['email']; echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Type: " . $_FILES["file"]["type"] . "
"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
"; if ((($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg")) && ($_FILES["file"]["size"] < 2000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "
"; } else { echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Type: " . $_FILES["file"]["type"] . "
"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
"; } } else { echo "Invalid file"; } if(!$name || !$address || !$city) { echo <<<HTML Please fill out all the mandatory fields. HTML; } else { $mess = <<<HTML -------------------------------------------------------- You've got a message for FREE sample of Partymagnets.ca -------------------------------------------------------- Full name: {$name} Address: {$address} City: {$city} PostalCode: {$postalcode} Caption on Magnet: {$caption} Phone number: {$phone} Email Address: {$email} Path: {$target_path} ----------------------------------------------- HTML; mail("[email protected]","Email from Partymagnets.ca - FREE sample",$mess); echo <<<HTML Thank you, We will send you the FREE magnet sample within 5 business days. HTML; } } else { header("location: freeMagnetSample.html"); } ?>

[/php]

hope it is not too messy…

try this
[php]

<?php if(isset($_POST['submit'])) { $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['file']['name']); if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['file']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } echo $target_path . "
"; $name = $_POST['fullname']; $address = $_POST['address']; $postalcode = $_POST['postalcode']; $city = $_POST['city']; $caption = $_POST['caption']; $phone = $_POST['phone']; $email = $_POST['email']; echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Type: " . $_FILES["file"]["type"] . "
"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
"; if ((($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg")) && ($_FILES["file"]["size"] < 2000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "
"; } else { echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Type: " . $_FILES["file"]["type"] . "
"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
"; } } else { echo "Invalid file"; } if(!$name || !$address || !$city) { echo <<<HTML Please fill out all the mandatory fields. HTML; } else { $mess = <<<HTML -------------------------------------------------------- You've got a message for FREE sample of Partymagnets.ca -------------------------------------------------------- Full name: {$name} Address: {$address} City: {$city} PostalCode: {$postalcode} Caption on Magnet: {$caption} Phone number: {$phone} Email Address: {$email} Path: {$target_path} ----------------------------------------------- HTML; mail("[email protected]","Email from Partymagnets.ca - FREE sample",$mess); echo <<<HTML Thank you, We will send you the FREE magnet sample within 5 business days. HTML; } } else { { header("location: freeMagnetSample.html"); } ?>

[/php]

Thanks sergo_bero.

This is what I get…

Sorry, there was a problem uploading your file.uploads/
Upload:
Type:
Size: 0 Kb
Temp file:
Invalid file

umm… you just added the isset() right? (I did c/p for all the code and replaced it with mine…)

<form id="form1" action="uploadedFile.php" method="post" runat="server">

replace with

<form id="form1" action="uploadedFile.php" method="post" runat="server" enctype="multipart/form-data">

It works !!!
Thank you so much !!!

Can you tell why this change (enctype=“multipart/form-data”>) made the difference?

enctype is used to specifies type of form, you should use enctype=“multipart/form-data” everytime you use input type=‘file’
Some comments about this at :
http://www.htmlcodetutorial.com/forms/_FORM_ENCTYPE.html

Sponsor our Newsletter | Privacy Policy | Terms of Service