Guest_imported
New member
- Jan 1, 1970
- 0
I have a working php ftp upload modual that works perfectlly for uploading '.txt' files. I have been trying to get this to upload pictures instead, but I can not seem to get it to work properly. What happens is I get the picture icon but with no data inside the picture.
This is the script that will work properly for txt files, does anybody now how to modifiy this to upload 'gif', 'jpeg', 'png'? Thanks in advance for anybody that could help me out. This modual is open source, please feel free to use.
This is broken into two pages for clarity.
//html for that links to the php upload page
<html>
<head>
<title>Administration - upload new files</title>
</head>
<body>
<h1>Upload new news files</h1>
<form enctype="multipart/form-data" action="upload.php" method=post>
<input type="hidden" name="MAX_FILE_SIZE" value="10000">
Upload this file:
<input name="userfile" type="file">
<input type="submit" value="Send File">
</form>
</body>
</html>
//php upload page
<html>
<head>
<title>Uploading...</title>
</head>
<body>
<h1>Uploading file...</h1>
<?
// $userfile is where file went on webserver
// $userfile_name is original file name
// $userfile_size is size in bytes
// $userfile_type is mime type e.g. image/gif text/plain
echo "Variables are:<br>";
echo "userfile: ".$userfile."<br>userfile_name: ".$userfile_name."<br> userfile_size: ".$userfile_size."<br>userfile_type: ".$userfile_type."<br>End variables<br><br>";
if ($userfile=="none"
{
echo "Problem: no file uploaded";
exit;
}
if ($userfile_size==0)
{
echo "Problem: uploaded file is zero length";
exit;
}
if ($userfile_type != "text/plain" //'image/gif' doesnt work correctly
{
echo "Problem: file is not plain text";
exit;
}
$upfile = "images/".$userfile_name;
if ( !copy($userfile, $upfile))
{
echo "Problem: Could not move file into directory";
exit;
}
echo "File uploaded successfully<br><br>";
$fp = fopen($upfile, "r"
$contents = fread ($fp, filesize ($upfile));
fclose ($fp);
$contents = strip_tags($contents);
$fp = fopen($upfile, "w"
fwrite($fp, $contents);
fclose($fp);
echo "Preview of uploaded file contents:<br><hr>";
echo $contents;
echo "<br><hr>";
?>
</body>
</html>
This is the script that will work properly for txt files, does anybody now how to modifiy this to upload 'gif', 'jpeg', 'png'? Thanks in advance for anybody that could help me out. This modual is open source, please feel free to use.
This is broken into two pages for clarity.
//html for that links to the php upload page
<html>
<head>
<title>Administration - upload new files</title>
</head>
<body>
<h1>Upload new news files</h1>
<form enctype="multipart/form-data" action="upload.php" method=post>
<input type="hidden" name="MAX_FILE_SIZE" value="10000">
Upload this file:
<input name="userfile" type="file">
<input type="submit" value="Send File">
</form>
</body>
</html>
//php upload page
<html>
<head>
<title>Uploading...</title>
</head>
<body>
<h1>Uploading file...</h1>
<?
// $userfile is where file went on webserver
// $userfile_name is original file name
// $userfile_size is size in bytes
// $userfile_type is mime type e.g. image/gif text/plain
echo "Variables are:<br>";
echo "userfile: ".$userfile."<br>userfile_name: ".$userfile_name."<br> userfile_size: ".$userfile_size."<br>userfile_type: ".$userfile_type."<br>End variables<br><br>";
if ($userfile=="none"
{
echo "Problem: no file uploaded";
exit;
}
if ($userfile_size==0)
{
echo "Problem: uploaded file is zero length";
exit;
}
if ($userfile_type != "text/plain" //'image/gif' doesnt work correctly
{
echo "Problem: file is not plain text";
exit;
}
$upfile = "images/".$userfile_name;
if ( !copy($userfile, $upfile))
{
echo "Problem: Could not move file into directory";
exit;
}
echo "File uploaded successfully<br><br>";
$fp = fopen($upfile, "r"
$contents = fread ($fp, filesize ($upfile));
fclose ($fp);
$contents = strip_tags($contents);
$fp = fopen($upfile, "w"
fwrite($fp, $contents);
fclose($fp);
echo "Preview of uploaded file contents:<br><hr>";
echo $contents;
echo "<br><hr>";
?>
</body>
</html>