Jump to content

Simple Upload Script (3owl.com)


Go to solution Solved by phpcoder2013,

Recommended Posts

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:

 

 

 

<?php
if((!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 by phpcoder2013
Link to comment
https://forums.phpfreaks.com/topic/281438-simple-upload-script-3owlcom/
Share on other sites

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.