Jump to content

Basic file upload? Only works locally..


dirntknow

Recommended Posts

Just trying this basic code for uploading a file (image) and works locally but I get a 500-Internal Error when uploaded to my site...why would this happen?

Thanks!!

 

<?php 
echo "<pre>";
print_r($_FILES);
echo "</pre>";
$target_path = "./upload/".$_FILES['uploadedfile']['name'];
move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$target_path);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<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" />
<input type="submit" value="Upload File" />
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/200043-basic-file-upload-only-works-locally/
Share on other sites

i use

 

// the foll 2 lines are in the file that the viewer see 
//<tr><td><font face="Tahoma" color="#0000FF" size="2"><b>Upload a file:</td><td><input name="userfile" 
//type="file"><font size="1" color="#FF0080"> File size should not exceed 2MB</font></td></tr><p><p>


if(!($_FILES["userfile"]["name"]=="")) 
{
$uploaddir="./filesadded/";
//copy the file to some permanent location 

if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploaddir.$_FILES["userfile"]["name"])) 
{
echo("<p>File uploaded<p><p>");
} 
else 
{
echo ("<p>Error in uploading file! Please try again.<br>");
if($_FILES['userfile']['error']==1) echo "<font color=red>Error: File size exceeds maximum permissible limit of 2MB</font><p><p>";
}
} 


Archived

This topic is now archived and is closed to further replies.

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