Jump to content

Recommended Posts

Hello,

I have a very simple script and am not interested in security. That being said, I cannot get it to work and I was wondering if you good people could help me find out why. I am an amateur as I am sure you all can tell so please be gentle 

 

Form.php

HTML:

 

<form enctype="multipart/form-data" action="uploader.php" method="POST">

<input type="hidden" name="MAX_FILE_SIZE" value="100000" />

Choose a file to upload: <input name="uploadedfile" type="file" /><br />

<input type="submit" value="Upload File" />

</form>

 

 

 

Uploader.php

php:

 

<html>

<head>

       

<title>Untitled</title>

 

</head>

<body>

 

<?

 

$target_path = "uploads/";

 

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

    echo "The file ".  basename( $_FILES['uploadedfile']['name']).

    " has been uploaded";

} else{

    echo "There was an error uploading the file, please try again!";

}

 

 

?>

</body>

</html>

 

 

 

I copied this verbatim from one of the tutorials so I am not trying to claim this as my own but I cannot get it to work. The only message I get after trying to upload is the "There was an error..." message. Any help is appreciated. Thanks in advance.

 

Link to comment
https://forums.phpfreaks.com/topic/71699-upload-code-question/
Share on other sites

"I have a very simple script and am not interested in security." - PLEASE don't start writing PHP code with this attitude, you'll get into problems later on.

 

And no, writable depends on permissions... check the permissions on the file (you can do it through cPanel if you have it)

Link to comment
https://forums.phpfreaks.com/topic/71699-upload-code-question/#findComment-362611
Share on other sites

it means you got a pain in the neck of an Error. Let me go through your code again.

I got nothing :-\

 

compare your script to this working upload script and see if you can get something from it.

HTML:

<form action="uploader.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" size="45">
<br>
<input type="submit" value="Upload File">
</form>

 

uploader.php:

<?php
if( $_FILES['file']['name'] != "" ) // theirs your first bit of security, its really not hard 
{
  copy ( $_FILES['file']['tmp_name'],
  "C:/Apache/htdocs/" . $_FILES['file']['name'] ) // the directory to send the file
  or die( "Could not copy file" ); // more security
  }
  else{ die( "No file specified" ); } // the last of the security
?>

 

see what you come up with, you might just trip over the answer you've been looking for.

 

Regards ACE

Link to comment
https://forums.phpfreaks.com/topic/71699-upload-code-question/#findComment-363364
Share on other sites

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.