RRT
02-28-2012, 08:07 PM
Hi, I am trying to create a php file upload page where JPG images can be uploaded to the server. Below are the 2 php pages that should give this functionality. For some reason it is not working. Do you have any idea as to why this file upload not work?:
upload.php
<?php
echo "<HTML>\n";
echo "<TITLE>Upload a file</TITLE>\n";
echo "<BODY>\n";
echo "<form action=\"do_upload.php\" method=\"post\" enctype=\"multipart/form-data\">\n";
echo "<P><STRONG>File to Upload:</STRONG><BR>\n";
echo "<input type=\"file\" name=\"file\">\n";
echo "<P><input type=\"submit\" name=\"submit\" value=\"Upload image\">\n";
echo "<input type=\"reset\" value=\"reset\" name=\"Reset\">";
echo "</form>";
echo "</body>";
echo "</html>";
do_upload.php:
<?php
$img1_name = $_POST[img1];
$img1_type = $_POST[file];
echo " " . trim($img1) . "\n";
echo " " . trim($img1_name) . "\n";
echo "\n";
echo "<P><HR>";
if (is_uploaded_file($img1_name)) {
move_uploaded_file($img1_name, "/var/www/html/acme/$img1_name") or die("<H3><FONT COLOR=RED>ERROR 2 : (error uploading image file to portal)</H3><HR><FONT COLOR=BLACK> <LI>Couldn't copy the file. Please contact Technical Support.");
}
else {
die("<H3><FONT COLOR=RED>ERROR 1 : (error uploading image file to portal)</H3><HR><FONT COLOR=BLACK> <LI>No input file specified. Select a file first before clicking the <I>Upload File</I> button.");
}
?>
<HTML>
<HEAD>
<TITLE>Upload Status...</TITLE>
</HEAD>
<BODY>
<H1>Success!</H1>
</BODY>
</HTML>
Do you see any syntax or logic errors as to why this isn't working properly? During the 'if-else' block, it's just going to the 'die' section where it says "ERROR 1".
upload.php
<?php
echo "<HTML>\n";
echo "<TITLE>Upload a file</TITLE>\n";
echo "<BODY>\n";
echo "<form action=\"do_upload.php\" method=\"post\" enctype=\"multipart/form-data\">\n";
echo "<P><STRONG>File to Upload:</STRONG><BR>\n";
echo "<input type=\"file\" name=\"file\">\n";
echo "<P><input type=\"submit\" name=\"submit\" value=\"Upload image\">\n";
echo "<input type=\"reset\" value=\"reset\" name=\"Reset\">";
echo "</form>";
echo "</body>";
echo "</html>";
do_upload.php:
<?php
$img1_name = $_POST[img1];
$img1_type = $_POST[file];
echo " " . trim($img1) . "\n";
echo " " . trim($img1_name) . "\n";
echo "\n";
echo "<P><HR>";
if (is_uploaded_file($img1_name)) {
move_uploaded_file($img1_name, "/var/www/html/acme/$img1_name") or die("<H3><FONT COLOR=RED>ERROR 2 : (error uploading image file to portal)</H3><HR><FONT COLOR=BLACK> <LI>Couldn't copy the file. Please contact Technical Support.");
}
else {
die("<H3><FONT COLOR=RED>ERROR 1 : (error uploading image file to portal)</H3><HR><FONT COLOR=BLACK> <LI>No input file specified. Select a file first before clicking the <I>Upload File</I> button.");
}
?>
<HTML>
<HEAD>
<TITLE>Upload Status...</TITLE>
</HEAD>
<BODY>
<H1>Success!</H1>
</BODY>
</HTML>
Do you see any syntax or logic errors as to why this isn't working properly? During the 'if-else' block, it's just going to the 'die' section where it says "ERROR 1".