Jump to content

php upload file not working inside a form


mamaomphile

Recommended Posts

Good Day

 

need help, been trying this for so long now,  i have a code for move_upload_file()  it works very fine when i test the page alone but once i put it on the form on my website it doesnt work?

here is my code - upload_file.php :

 

<?php
error_reporting(E_ALL);
$allowedExts = array("gif", "jpeg", "jpg",  "jpe", "png", "pjpeg", "x-png");
$allowedMimeTypes = array( 'application/msword','text/pdf','image/gif','image/jpeg','image/png');
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/jpe")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 500000)
&& 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"] / 1024) . " kB<br>";
 echo "Stored in: " . $_FILES["file"]["tmp_name"];
 
 if (file_exists("Images/" . $_FILES["file"]["name"]))
 {
 echo $_FILES["file"]["name"] . " already exists. ";
 
 }
else
 {
     chmod ("Images/", 0775);
 
 if (copy($_FILES["file"]["tmp_name"],"Images/" . $_FILES["file"]["name"])) {
 move_uploaded_file($_FILES["file"]["tmp_name"],"Images/" . $_FILES["file"]["name"]);
         echo "Stored in: " . "Images/" . $_FILES["file"]["name"];
  }
 
}
 }
}
else
 {
 echo "Invalid file";
 }
?>
 
 
Inside my form i have this link
<?php
include "/cmsintranet/testing.php";
?>
 
that is calling a testing.php page which looks like this:
 
<html>
<body>
 
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<button type="reset" value="Reset">Reset</button><input type="submit" value="Submit" id="">
</form>
 
</body>
</html> 
 
Please help me out since am not sure what exactly is the problem whether its my website cos the pages works just fine?
 

check the ownership and permissions of the form script or which ever script is doing the uploading.  Depending on your setup, the web server (example apache) needs to own the script doing the uploading.  From the command line try:

chown apache:apache uploadscript.php

The permissions are set on my server but still not working and with no errors, i even tested the upload code on my server and the code works just fine the problem comes once i call it on the Form, am not sure what to do anymore.

my from looks like this:

 

<h3 id="menu_head">Adding Gallery</h3>
<form name="gallery" action="index.php?m=galleries&sm=newgallery&d=add" method="post">
<table id="form_table" align="center" width="60%">
 
<tr>
<td>Gallery Name:</td><td><input type="text" name="name" size="50" style="width:240px;"></td>
</tr>
<tr>
<td colspan="2"><br><strong>Description:</strong></td>
</tr>
<tr>
<td colspan="2"><textarea name="content"  cols="40" size="50" rows="5" style="width:500px; height:150px;"></textarea></td>
</tr>
<tr>
<td colspan="2" align="left">
                
               <?php include $_SERVER['DOCUMENT_ROOT']."/cmsintranet/testing.php";
                 ?>
 
</td>
</tr>
       
</table>
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.