FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 12th, 2002, 05:44 PM
jahu jahu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 110 jahu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 16 m 17 sec
Reputation Power: 11
ftp upload ware

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>

Reply With Quote
  #2  
Old August 12th, 2002, 07:02 PM
merkinmuffley's Avatar
merkinmuffley merkinmuffley is offline
film at 11
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Portland, OR
Posts: 413 merkinmuffley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Maybe I can help without confusing the issue further...

1) The code checks the filetype explicitly, and it has to be "text/plain" or else the script stops. I would do something like this:
PHP Code:
 $typesOK = array("text/plain""image/gif""image/jpeg""image/png");
if (! 
in_array($userfile_type$typesOK))
{
    echo 
"Problem: file is not of acceptable type.";
    exit;



2) Your script reads in the data from the uploaded file and dumps it to the screen. You can't display an image just by dumping the data to a web page like that. The script copies the image to a place where it's accessible from the web, I think; all you have to do is put an image tag with the proper URL to display the image.

3) Don't use this check for an empty file upload:
PHP Code:
if ($userfile=="none")
{
    echo 
"Problem: no file uploaded";
    exit;


Beginning with (I think) version 4.2, when no file is uploaded the variable is no longer set to "none", instead it's just left blank. A better way is to always check the size; if $userfile_size is zero, then no file or an empty file was uploaded.

hth

/nick

Reply With Quote
  #3  
Old August 12th, 2002, 08:10 PM
jahu jahu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 110 jahu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 16 m 17 sec
Reputation Power: 11
That worked out perfectlly, thank you so much...

Reply With Quote
  #4  
Old August 12th, 2002, 08:27 PM
jahu jahu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 110 jahu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 16 m 17 sec
Reputation Power: 11
I have one other question about it though. Do you have any idea why 'image/gif' will upload, but 'image/jpg' and 'image/png' does not work?

$typesOK = array("image/jpeg", "image/png", "image/gif");
if (! in_array($userfile_type, $typesOK))
{
echo "Problem: file is not of acceptable type.";
exit;
}

I am getting this error for jpeg's and png's, but works for gif's. Thanks in advance...

Reply With Quote
  #5  
Old August 13th, 2002, 10:15 AM
merkinmuffley's Avatar
merkinmuffley merkinmuffley is offline
film at 11
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Portland, OR
Posts: 413 merkinmuffley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
I don't have an answer there.. what's the output of your debugging bit when you upload those types of files? When I wrote a script like this I took all the file types I wanted to accept, uploaded them and copied what PHP said the mime type was...

Reply With Quote
  #6  
Old August 13th, 2002, 02:58 PM
jahu jahu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 110 jahu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 16 m 17 sec
Reputation Power: 11
For some reason the output file types for jpg and png are screwy:

Jpeg output file type prints: 'image/pjpeg'
Png output file type prints: 'image/x-png'

Mabe these are not exceptable MIME types?

Reply With Quote
  #7  
Old August 13th, 2002, 03:01 PM
merkinmuffley's Avatar
merkinmuffley merkinmuffley is offline
film at 11
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Portland, OR
Posts: 413 merkinmuffley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Hmm... on closer inspection of my own script I see that I have these listed as acceptable mime types:
image/jpeg
image/pjpeg
image/gif

well, I am not sure why there are seemingly 2 mime types for jpeg. One of those is probably not correct and shouldn't be there. If I find anything else I'll post it here.

Reply With Quote
  #8  
Old August 13th, 2002, 03:38 PM
jahu jahu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 110 jahu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 16 m 17 sec
Reputation Power: 11
sounds good, thanks for all the help.

Reply With Quote
  #9  
Old September 5th, 2002, 03:12 PM
MrAlaska MrAlaska is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Boston
Posts: 1 MrAlaska User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
When investigating validating uploading images, I found this list to certify against and it seems to work. I am not familiar with all the types, but you might find this list helpful.

$cert1 = "image/pjpeg"; //Jpeg type 1
$cert2 = "image/jpeg"; //Jpeg type 2
$cert3 = "image/gif"; //Gif type
$cert4 = "image/ief"; //Ief type
$cert5 = "image/png"; //Png type
$cert6 = "image/tiff"; //Tiff type
$cert7 = "image/bmp"; //Bmp Type
$cert8 = "image/vnd.wap.wbmp"; //Wbmp type
$cert9 = "image/x-cmu-raster"; //Ras type
$cert10 = "image/x-x-portable-anymap"; //Pnm type
$cert11 = "image/x-portable-bitmap"; //Pbm type
$cert12 = "image/x-portable-graymap"; //Pgm type
$cert13 = "image/x-portable-pixmap"; //Ppm type
$cert14 = "image/x-rgb"; //Rgb type
$cert15 = "image/x-xbitmap"; //Xbm type
$cert16 = "image/x-xpixmap"; //Xpm type
$cert17 = "image/x-xwindowdump"; //Xwd type

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > ftp upload ware

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap