Jump to content

Recommended Posts

How would I create basic upload script. I just want an upload script so I can upload .php files to my webserver.

 

I have this code from php.net:

 

<?php
$uploaddir = 'C:/xampp/htdocs/xampp/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";  
?>

 

but, that always gives me a 'Possible file attack' error whenever i try and upload a .php file.

 

Can someone please fix that up so i can use it to upload .php files.

 

Thanks, Daniel

Link to comment
https://forums.phpfreaks.com/topic/54847-upload-script/
Share on other sites

Why don't you just use FTP? Anyway, there is abit of a code here which a wrote a while ago, so I am not too sure whether it works, ect. As I can't remember.

 

This lets you upload any type of file to a certain folder, with a browse button too. You could, create a drop down list, or radio buttons to make it upload to a different folder. The only thing is though, I think you have to set the folder permissions to 777, before you can use this script, otherwise it just dosen't allow it.

 

Let me know how it goes,

<?php
//set where you want to store files
//in this example we keep file in folder upload 
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "upload/".$HTTP_POST_FILES['ufile']['name']; // change "upload/" to the location on the server
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "<h1>Successful</h1><BR/>"; 

//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "<strong>File Name :</strong>".$HTTP_POST_FILES['ufile']['name']."<BR/>"; 
echo "<strong>File Size :</strong>".$HTTP_POST_FILES['ufile']['size']."<BR/>"; 
echo "<strong>File Type :</strong>".$HTTP_POST_FILES['ufile']['type']."<BR/>"; 
}
else
{
echo "Error";
}
}
?>

 

From Cal

Link to comment
https://forums.phpfreaks.com/topic/54847-upload-script/#findComment-271354
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.