mamaomphile Posted January 22, 2014 Share Posted January 22, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/285585-php-upload-file-not-working-inside-a-form/ Share on other sites More sharing options...
jazzman1 Posted January 22, 2014 Share Posted January 22, 2014 Any error messages? And describe the phrase, " it doesnt work", it's a very common phrase in the forum Quote Link to comment https://forums.phpfreaks.com/topic/285585-php-upload-file-not-working-inside-a-form/#findComment-1466174 Share on other sites More sharing options...
rwhite35 Posted January 22, 2014 Share Posted January 22, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/285585-php-upload-file-not-working-inside-a-form/#findComment-1466225 Share on other sites More sharing options...
mamaomphile Posted January 30, 2014 Author Share Posted January 30, 2014 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> Quote Link to comment https://forums.phpfreaks.com/topic/285585-php-upload-file-not-working-inside-a-form/#findComment-1467049 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.