Hello,
I am working on a portfolio web app to add projects to an online portfolio.
I am trying to make it so that I have a Form.php file and a Processor.php file. I want the form to upload an Image to the directory “portfolio/images/full/”. As well as an Image Thumbnail to the directory “portfolio/images/thumb/”. I have tried combining a couple of different ways I saw around and this is what I came up with, however its not working. If I print_r the array $key[], it shows it as empty.
portfolio_Form.php
[CODE]
<form name=”addPortfolioProject” action=”portfolio_Processor.php” method=”post”>
<div style=”display: block; width: 600px; height: 50px; float: left;”>
<input required title=”Project Name is Required!” type=”text” name=”projName” size=”40″ value=”Project Name” style=”font-size: larger;” />
</div>
<div class=”clear”></div>
<div style=”width: 300px; float: left;”>
<h4 style=”padding-bottom: 10px;”>Full Image</h4>
<img src=”images/addProjImage.jpg” width=”300″ alt=”Add Image” /><br />
<input required title=”Full Image is Required!” id=”file1″ type=”file” name=”file[]” />
</div>
<div style=”width: 180px; float: left; margin-left: 60px;”>
<h4 style=”padding-bottom: 10px;”>Image Thumbnail</h4>
<img src=’images/addProjThumb.jpg’ alt=’Add Project Thumbnail’ width=’100px’ />
<input required title=”Image Thumbnail is Required!” id=”file2″ type=”file” name=”file[]” />
</div>
<div class=”clear”></div>
<div>
<div style=”width: 377px; float: left;”>
<h2 style=”border-bottom: solid #1b5799 2px;”>Project Description</h2>
<textarea required title=”Project Description is Required!” name=”projDescription” cols=”60″ rows=”6″ style=”font-family: Calibri, Cambria, ‘Times New Roman’;”></textarea>
</div>
</div>
<div class=”clear”></div>
<div>
<input type=”submit” name=”submit” />
</div>
</form>
That submits to the following ‘processor’ page
portfolio_Processor.php
[CODE]
<?php
$projName = $_POST[‘projName’];
$projDescription = $_POST[‘projDescription’];
$projImgFull = “”;
$projImgThumb = “”;
if ((($_FILES[“projImgFull”][“type”] == “image/gif”) || ($_FILES[“projImgFull”][“type”] == “image/jpeg”)
|| ($_FILES[“projImgFull”][“type”] == “image/jpg”))) {
if ($_FILES[“projImgFull”][“error”] > 0) {
echo “Return Code: ” . $_FILES[“projImgFull”][“error”] . “<br />”;
}
else {
echo “Upload: ” . $_FILES[“projImgFull”][“name”] . “<br />”;
echo “Type: ” . $_FILES[“projImgFull”][“type”] . “<br />”;
echo “Size: ” . ($_FILES[“projImgFull”][“size”] / 1024) . ” Kb<br />”;
echo “Temp file: ” . $_FILES[“projImgFull”][“tmp_name”] . “<br />”;
if (file_exists(“portfolio/images/full/” . $_FILES[“projImgFull”][“name”])) {
echo $_FILES[“file”][“name”] . ” already exists. “;
}
else {
move_uploaded_file($_FILES[“projImgFull”][“tmp_name”],
“upload/” . $_FILES[“projImgFull”][“name”]);
echo “Stored in: ” . “portfolio/images/full/” . $_FILES[“projImgFull”][“name”];
$projImgFull = “portfolio/images/full/” . $_FILES[“projImgFull”][“name”];
}
}
} else {
echo “Invalid file”;
}
if ((($_FILES[“projImgThumb”][“type”] == “image/gif”) || ($_FILES[“projImgThumb”][“type”] == “image/jpeg”)
|| ($_FILES[“projImgThumb”][“type”] == “image/jpg”))) {
if ($_FILES[“projImgThumb”][“error”] > 0) {
echo “Return Code: ” . $_FILES[“projImgThumb”][“error”] . “<br />”;
}
else {
echo “Upload: ” . $_FILES[“projImgThumb”][“name”] . “<br />”;
echo “Type: ” . $_FILES[“projImgThumb”][“type”] . “<br />”;
echo “Size: ” . ($_FILES[“projImgThumb”][“size”] / 1024) . ” Kb<br />”;
echo “Temp file: ” . $_FILES[“projImgThumb”][“tmp_name”] . “<br />”;
if (file_exists(“portfolio/images/thumb/” . $_FILES[“projImgThumb”][“name”])) {
echo $_FILES[“projImgThumb”][“name”] . ” already exists. “;
}
else {
move_uploaded_file($_FILES[“projImgThumb”][“tmp_name”],
“upload/” . $_FILES[“projImgThumb”][“name”]);
echo “Stored in: ” . “portfolio/images/thumb/” . $_FILES[“projImgThumb”][“name”];
$projImgFull = “portfolio/images/thumb/” . $_FILES[“projImgThumb”][“name”];
}
}
} else {
echo “Invalid file”;
}
?>