PHP File Uploader leading to "Page not Found" - php

I've put together an HTML Form for a PHP File Uploader but when I use the form and attempt to upload the file I get sent to a "Page not Found" and the file never ends up where it's supposed to on my server.
Here's the Form:
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<p><font size="2">*=Required</font></p>
<b>Mod Name:*</b><br /><input type="text" name="modname" size="30"><br />
<b>Author:*</b><br /><input type="text" name="author" size="30"><br />
<b>Version:*</b><br /><input type="text" name="version" size="30"><br /><br />
<b>Game:</b><select>
<option value="morrowind">Morrowind</option>
<option value="oblivion">Oblivion</option>
<option value="skyrim">Skyrim</option>
</select><br /><br />
<p><b><font size="3">Dependencies:</font></b></p>
<p>Morrowind</p>
<input type="checkbox" value="expansion" name="tribunal" />Tribunal <br />
<input type="checkbox" value="expansion" name="bloodmoon" />Bloodmoon <br />
<input type="checkbox" value="mod" name="mge" />MGE <br />
<input type="checkbox" value="mod" name="mwe" />MWE <br />
<input type="checkbox" value="mod" name="mwse" />MWSE <br />
<p>Oblivion</p>
<input type="checkbox" value="expansion" name="knights" />Knights of the Nine <br />
<input type="checkbox" value="expansion" name="isle" />Shivering Isles <br />
<p>Skyrim</p>
<input type="checkbox" value="expansion" name="dawnguard" />Dawnguard <br /><br />
<label for="description"><b>Description:</b></label><br />
<textarea id="description" rows="4" cols="50"></textarea><br /><br />
<b>Uploader Name:</b><br /><input type="text" name="upname" size="30"><br /><br />
<label><b>Uploader Comments</b></label><br />
<textarea id="uploader" rows="4" cols="50"></textarea><br /><br />
<b>Mirror Links:</b><br /><input type="text" name="mirror" size="50"><br /><br />
<label for="file"><b>Upload Mod:</b></label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
<p><font size="2">Maximum File Size: 400MB; Only Compressed Files Accepted (.zip, .rar, .7z)</font></p>
</form>
and here's the upload php file:
<?php
$allowedExts = array("zip, rar, 7z");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "application/zip")
|| ($_FILES["file"]["type"] == "application/x-rar-compressed")
|| ($_FILES["file"]["type"] == "application/x-7z-compressed"))
&& ($_FILES["file"]["size"] < 419430401)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 400) . " Mb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
if (file_exists("uploads/mods/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"uploads/mods/" . $_FILES["file"]["name"]);
echo "Stored in: " . "uploads/mods/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
Where did I mess up?
Do I need to place the .php file inside of the upload directory? Where does the form information go? Also, how do I require some of the text boxes in the form?
Thanks, I'm a bit lost here.

You can check the web server logs (like suggested before) to see if they give you an idea (usually they do). Without knowing your file/directory structure, it's pretty much guesswork. I noticed the form references upload_file.php, then you call the second code upload php. Is it just misnamed?
Also, make sure it is in the same directory as the HTML file with your form.
If you want the upload_file.php file to be in a subdirectory, you can do this by changing:
<form action="upload_file.php" method="post" enctype="multipart/form-data">
to:
<form action="subdirectory/upload_file.php" method="post" enctype="multipart/form-data">

Related

Picture uploading proble

I don't have an idea why it doesn't upload pictures(But the same peace of code does). Please help me.
HTML:
$max_filesize = 524288;
$upload_path = './img/';
$id=$_POST["id"];
for ($i=1; $i<=3; $i++)
{
(string)$inside="inside".$i;
echo $inside;
$filename = $_FILES[$inside]['name'];
echo $filename;
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
echo $ext;
if (isset($_POST[$inside])){
if(filesize($_FILES[$inside]['tmp_name']) > $max_filesize)
die('File is too big.');
if(!is_writable($upload_path))
die('Cannot access folder - 777.');
if(move_uploaded_file($_FILES[$inside]['tmp_name'],$upload_path . $id . "inside" . $i . $ext))
{
echo 'Uploaded successfuly ';
echo '<br><br>';
echo '<img src="' . $upload_path . $filename . '" width="300" >';
} else {
echo 'Something went wrong, try again.';
}
}
}
Before that:
<form method="post" enctype="multipart/form-data" action=""/>
Що в коробці(Фото): <p>
<input type="file" name="inside1"
accept=".jpg, .jpeg, .png"> <p>
<input type="file" name="inside2"
accept=".jpg, .jpeg, .png"> <p>
<input type="file" name="inside3"
accept=".jpg, .jpeg, .png"> <p>
</form>
It says 'Something went wrong, try again.'.
Strange form - <form></form>
<form action="<?php echo'admin/photo_upload.php'; ?>" enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size; ?>" />
<p><input name="file_upload[]" type="file" id="file_upload[]" value=""></p>
<p><input name="file_upload[]" type="file" id="file_upload[]" value=""></p>
<p>Caption: <input type="text" name="caption" value="" /></p>
<input type="submit" name="submit" value="Upload" />

Image Upload Not Working, Receiving No Errors

Here's my HTML form:
<form class="plist" action="build/build.php" method="_POST" enctype="multipart/form-data">
<label>Package Name: </label>
<input type="text" name="packageName">
<br />
<br />
<label>Package Description: </label>
<textarea rows="4" cols="20" type="text" name="packageDescription"></textarea>
<br />
<br />
<label>Website: </label>
<input type="text" name="packageWebsite">
<br />
<br />
<label>Contact: </label>
<input type="text" name="packageContact">
<br />
<br />
<label>Price: </label>
<input type="text" name="packagePrice">
<br />
<br />
<label>Screenshots: </label>
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="file" name="packageScreenshots" id="packageScreenshots">
<br />
<br />
<button type="submit" name="submit" value="submit">Build</button>
</form>
and build.php:
if($_SERVER['REQUEST_METHOD'] == 'POST' && $_FILES['packageScreenshots']['error'] == 'UPLOAD_ERR_OK'){
$uploaddir = '/zips/uploads/';
$uploadfile = $uploaddir . basename($_FILES['packageScreenshots']['name']);
list($width, $height, $type, $attr) = getimagesize($_FILES['packageScreenshots']['tmp_name']);
if (move_uploaded_file($_FILES['packageScreenshots']['tmp_name'], $uploadfile)) {
echo "File was successfully uploaded.\n";
} else {
echo "Hmm...";
}
};
// Create the zipped folder using ZipArchive()
$zip = new ZipArchive;
$full = $zip->open("/zips/$packageName.zip", ZipArchive::CREATE);
$zip->addFile('/zips/uploads/install.plist', 'install.plist');
$zip->addFile('/zips/uploads/google.png', 'google.png');
$zip->close();
The ZipArchive() function works great, there's stuff above what I showed in build.php where install.plist is created, that works fine, the .plist is created under the correct directory and compiled into the zip. When selecting and image for upload, the image isn't found under /zips/uploads/ like it should be. Haven't been able to get it to work on either localhost or on my server. Tried PHP 5.4 through 7.1 (GoDaddy), with the zip library enabled. The directories have correct permissions as well.
Try changing _POST to POST. :)

PHP uploader uploads 1 file only

I have a uploader in my page that is design to work from iPad and have 8 upload boxes.
When i upload pictures in the uploader, only one files is saved.
How can i get it to save all the pictures that gets uploaded?
folder is set to 777.
The Page
PHP:
<?
if ( isset( $_POST['submit'] ) ){
foreach ($_FILES['file']['name'] as $_key => $_value){
if($_FILES['file']['size'][$_key] !==0){
$randomizer = rand(0000000, 9999999);
$f=$randomizer.$_FILES['file']['name'][$_key];
echo $f;
echo "<br>";
$t=$_FILES['file']['tmp_name'][$_key];
echo $t;
echo "<br>";
//echo $_FILES['file']['size'][$_key]."<br />";
$file_mb = round(($_FILES["file"]["size"][$_key] / 1048576), 2);
echo "Size: " . $file_mb . " Mb<br />";
echo $_FILES['file']['type'][$_key]."<br />";
if( file_exists($t) ){ move_uploaded_file($t, 'upload/' . $f); }
//move_uploaded_file($_FILES['file']['tmp_name'][$_key], "upload"/$_FILES['file']['name'][$_key]);
echo "ok file";
echo "<br>";
}
}
}
?>
<form id="main_form" action="" method="POST" enctype="multipart/form-data">
<? for($i = 0; $i < 9; $i++) {
echo "<input type=\"file\" name=\"file[]\" /> <br>";
}
?>
<input type="submit" name="submit" value="send">
</form>
HTML:
<input type="file" name="image1" /><br /> <br /> <br />
<input type="file" name="image2" /><br /> <br /> <br />
<input type="file" name="image3" /><br /> <br /> <br />
<input type="file" name="image4" /><br /> <br /> <br />
<input type="file" name="image5" /><br /> <br /> <br />
<input type="file" name="image6" /><br /> <br /> <br />
<input type="file" name="image7" /><br /> <br /> <br />
<input type="file" name="image8" /><br /> <br /> <br />

File Upload and input text fields together

I have file upload and text input fields in my form and what I want is to show the error message for file upload on same page and don't go to the next page if there is error...if there is error on file upload return also the values of text fields to the same page... How I do it?
<form action="send.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="submited" value="true" /><br>
<label for="file">Choose Photo:</label>
<input type="file" name="file" required><br>
First Name:<input type="text" name="fname" required><br>
Last Name:<input type="text" name="lname" required><br>
Choose Username:<input type="text" name="username" required><br>
Age:<input type="text" name="age" required><br>
<input type="submit" value="Submit" name="submit" >
</form>
</body>
</html>
Here is the php code for file upload....I will be inserting the data from <input type="text"> to database and I don't have the code for it now...
<?php
ini_set( "display_errors", 0);
if(isset($_REQUEST['submited'])) {
// your save code goes here
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2097152)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "";
if (file_exists("images/" . $_FILES["file"]["name"]))
{
echo "<font color='red'><b>We are sorry, the file you trying to upload already exists.</b></font>";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"images/" . $_FILES["file"]["name"]);
echo "<font color='green'><b> Success! Your photo has been uploaded.</b></font>";
}
}
}
else
{
echo "<font color='red'><b>We are sorry, the file you trying to upload is not an image or it exceeds 2MB in size.</b></font><br><font color='blue'><i>Only images under size of 2MB are allowed</i></font>.";
}
}
?>
Just get your PHP to regenerate the form with the fields filled in (i.e. sst the value attribute) in the event of an error.
Heey,
To keep it on the same page u can remove the action
send.php
And then add the html and php code showed here in the same file. When that file is executed it will stay on the same page.
<?php
if (!empty($_POST)){
//send.php code
}
?>
<form action="send.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="submited" value="true" /><br>
<label for="file">Choose Photo:</label>
<input type="file" name="file" required><br>
First Name:<input type="text" name="fname" required><br>
Last Name:<input type="text" name="lname" required><br>
Choose Username:<input type="text" name="username" required><br>
Age:<input type="text" name="age" required><br>
<input type="submit" value="Submit" name="submit" >
</form>

move_uploaded_file not working as it should

I've searched around but I can't find my issue. I have a simple script that uploads a file to the target-folder.
$target = "img/fotos-artikels/";
$target .= basename($_FILES["uploadBron"]["name"]);
if(move_uploaded_file($_FILES["uploadBron"]["tmpname"], $target)) {
echo "The file " . basename($_FILES["uploadBron"]["name"]) . " has been uploaded.";
} else {
echo " Sorry there was a problem";
}
And this is the form:
<form enctype="multipart/form-data" action="" method="post">
<label for="txtBronNaam">Naam:</label>
<input type="text" name="txtBronNaam" id="txtBronNaam" value="" /><br />
<label for="uploadBron">File:</label>
<input type="file" name="uploadBron" id="uploadBron" value="" /><br />
<input type="submit" name="" value="Voeg bron toe" />
</form>
Do I have to enable something in apache maybe?
tmpname should be tmp_name

Categories