/    Sign up×
Community /Pin to ProfileBookmark

Uploading Multiple Files to Separate Locations

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>
[/CODE]

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”;
}
?>
[/CODE]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @ondo915 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...