phpcoder2013 Posted August 21, 2013 Share Posted August 21, 2013 (edited) Hello, I have a free account on 3owl.com and they support php versions 5.2, 5.3 and 5.4. (Using version 5.3) I was wondering how to create a simple upload script.(Does not need to be secure but I would like it to be secure) I currently have the following code in upload.php: <?phpif((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {$filename = basename($_FILES['uploaded_file']['name']);$ext = substr($filename, strrpos($filename, '.') + 1);if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") &&($_FILES["uploaded_file"]["size"] < 350000000)) {$newname = dirname(__FILE__).'/upload/'.$filename;if (!file_exists($newname)) {if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {echo "It's done! The file has been saved as: ".$newname;} else {echo "Error: A problem occurred during file upload!";}} else {echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";}} else {echo "Error: Only .jpg images under 350 000Kb are accepted for upload";}} else {echo "Error: No file uploaded";} ?> ...the following in Uploader.htm: <html> <body> <form enctype="multipart/form-data" action="upload.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> Choose a file to upload: <input name="uploaded_file" type="file" /> <input type="submit" value="Upload" /> </form> </body> </html> ...and the error message when I press upload: Warning: move_uploaded_file(/home/u313428959/public_html/upload/Random_Image.jpg): failed to open stream: No such file or directory in /home/u313428959/public_html/upload.php on line 14 Warning: move_uploaded_file(): Unable to move '/tmp/phpIxuO7X' to '/home/u313428959/public_html/upload/Random_Image.jpg' in /home/u313428959/public_html/upload.php on line 14 Error: A problem occurred during file upload! PS: I have only started learning to code PHP yesterday (Aug, 20, 2013 Tuesday) but I have had prior knowledge of HTML, Javascript and CSS. Edited August 21, 2013 by phpcoder2013 Quote Link to comment https://forums.phpfreaks.com/topic/281438-simple-upload-script-3owlcom/ Share on other sites More sharing options...
fastsol Posted August 21, 2013 Share Posted August 21, 2013 Here is a good tutorial series to get you started. http://www.youtube.com/playlist?list=PL10C2E583722F66E7 Quote Link to comment https://forums.phpfreaks.com/topic/281438-simple-upload-script-3owlcom/#findComment-1446169 Share on other sites More sharing options...
phpcoder2013 Posted August 21, 2013 Author Share Posted August 21, 2013 Can't you just provide the source for me? The codes I tried just don't work on 3owl.com but work on other servers Quote Link to comment https://forums.phpfreaks.com/topic/281438-simple-upload-script-3owlcom/#findComment-1446175 Share on other sites More sharing options...
fastsol Posted August 21, 2013 Share Posted August 21, 2013 Can't you just provide the source for me? The codes I tried just don't work on 3owl.com but work on other servers If that is the case it's probably the restrictions on the 3owl server that is the problem. Quote Link to comment https://forums.phpfreaks.com/topic/281438-simple-upload-script-3owlcom/#findComment-1446177 Share on other sites More sharing options...
phpcoder2013 Posted August 21, 2013 Author Share Posted August 21, 2013 If that is the case it's probably the restrictions on the 3owl server that is the problem. But it says: Warning: move_uploaded_file(/home/u313428959/public_html/upload/Random_Image.jpg): failed to open stream: No such file or directory in /home/u313428959/public_html/upload.php on line 14 Warning: move_uploaded_file(): Unable to move '/tmp/phpIxuO7X' to '/home/u313428959/public_html/upload/Random_Image.jpg' in /home/u313428959/public_html/upload.php on line 14 Error: A problem occurred during file upload! Quote Link to comment https://forums.phpfreaks.com/topic/281438-simple-upload-script-3owlcom/#findComment-1446188 Share on other sites More sharing options...
Solution phpcoder2013 Posted August 22, 2013 Author Solution Share Posted August 22, 2013 Thank you anyways. I somehow fixed the code while fiddling with it. Quote Link to comment https://forums.phpfreaks.com/topic/281438-simple-upload-script-3owlcom/#findComment-1446375 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.