pillbug Posted December 13, 2008 Share Posted December 13, 2008 Hi, I am trying to learn how to do upload script. I am practicing with script I found online, I did not write this (I will put the script at the end of this post) However, I get this error after I host it: Warning: move_uploaded_file(upload/00bg.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/a6190267/public_html/uploadFile.php on line 25 <html> <body> <form action="uploadFile.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Link to comment https://forums.phpfreaks.com/topic/136874-how-to-uploading-a-file/ Share on other sites More sharing options...
napalm Posted December 14, 2008 Share Posted December 14, 2008 make sure <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> is inside a file called, uploadFile.php.... spelled just like that. http://www.mystored.info/up/ ive tested the script and it works fine... as you can see i run a upload site if you need help just email me :} but any ways make sure, the <html> <body> <form action="uploadFile.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> is in index.php and <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> is in fileUpload.php mmmkay :} all good. Link to comment https://forums.phpfreaks.com/topic/136874-how-to-uploading-a-file/#findComment-714982 Share on other sites More sharing options...
pillbug Posted December 14, 2008 Author Share Posted December 14, 2008 Thanks for the help, but I discovered the answer searching online. I never realized I could change the permissions on directories. This was the main issue. How would I modify this script to allow me to change the file name, if the one exists. if (file_exists("upload/" . $_FILES["file"]["name"])) So say I want to upload test.jpg The first time, it uploads test.jpg I upload another file called test.jpg (but different content) The next time, it uploads 1test.jpg I upload another file called test.jpg (but different content) The next time, it uploads 11test.jpg Link to comment https://forums.phpfreaks.com/topic/136874-how-to-uploading-a-file/#findComment-715172 Share on other sites More sharing options...
pillbug Posted December 14, 2008 Author Share Posted December 14, 2008 Solved my own question <?php $time=time (); $ran2 = $time."."; $target="upload/"; //This applies the function to our file //$ext = findexts ($_FILES['uploaded']['name']) ; $oldname=$_FILES["file"]["name"]; $newname=$time. $_FILES["file"]["name"]; if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/bmp") || ($_FILES["file"]["type"] == "image/tiff") ) && ($_FILES["file"]["size"] < 2000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $oldname . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists($target . $newname)) { echo $newname . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], $target . $newname); echo "Stored in: " . $target . $newname; } } } else { echo "Invalid file"; } ?> Link to comment https://forums.phpfreaks.com/topic/136874-how-to-uploading-a-file/#findComment-715380 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.