|
Posted by "jnoyes" on 09/17/05 20:00
Can someone tell me why, or better yet how I can make sure that PHP doesn't
turn my non-progressive jpegs to pjepgs on upload? Using the code below, if
I upload a non-progressive jpeg, PHP tells me that the file uploaded
successfully, and the file is of type pjpeg. How can I avoid this problem?
************************MY CODE***************************************
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
// specify the file to write to
$filename = 'portfolio.xml';
//specify the content to write
$somecontent =
"\r\n<portfolioItem><image>".$HTTP_POST_FILES['userfile']['name']."</image><
/portfolioItem>";
//<portfolioItem><image>images/bride10.jpg</image></portfolioItem>
// specify the directory where the uploaded file should end up //$path =
'images/' ; $path = 'PHP_Library/';
// specify the filetypes allowed
$allowed = array('image/gif','image/pjpeg','image/jpeg','image/png');
// specify the max filesize in bytes
$max_size = 200000;
///checks to see if file field is not null
if(isset($HTTP_POST_FILES['userfile']))
{
if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']))
{
if($HTTP_POST_FILES['userfile']['size'] < $max_size)
{
if(in_array($HTTP_POST_FILES['userfile']['type'],$allowed))
{
if(!file_exists($path . $HTTP_POST_FILES['userfile']['name']))
{
if(@rename($HTTP_POST_FILES['userfile']['tmp_name'],$path.$HTTP_POST_FILES['
userfile']['name']))
{
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
} if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "The file '".$HTTP_POST_FILES['userfile']['name']."' was uploaded
successfully";
fclose($handle);
}
//fopen($filename, 'a');
//fwrite ($filename, $somecontent);
//fclose($handle);
$html_output = '<br>';
$html_output .= 'File Name:
'.$HTTP_POST_FILES['userfile']['name'].'<br>';
$html_output .= 'File Size: '.$HTTP_POST_FILES['userfile']['size'].'
bytes<br>';
$html_output .= 'File Type:
'.$HTTP_POST_FILES['userfile']['type'].'<br>';
//echo "this is the name".['name'];
$image = $HTTP_POST_FILES['userfile']['name'] ;
}else{
$html_output = 'Upload failed!<br>';
if(!is_writeable($path))
{
$html_output = 'The Directory "'.$path.'" must be writeable!<br>';
}else{
$html_output = 'an unknown error ocurred.<br>';
}
}
}else{
$html_output = 'The file already exists<br>';
}
}else{
$html_output = 'Wrong file type<br>';
}
}else{
$html_output = 'The file is too big<br>';
}
}
}else{
$html_output = '<form method="post" enctype="multipart/form-data"
action="'.$_SERVER['PHP_SELF'].'">';
$html_output .= '<input type="file" name="userfile">';
$html_output .= '<input type="submit" value="upload">';
$html_output .= '</form>';
}
echo '<html><head><title>Uploader</title></head><body>';
echo $html_output;
echo '</body></html>';
?>
</body>
</html>
Navigation:
[Reply to this message]
|