By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,478 Members | 1,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,478 IT Pros & Developers. It's quick & easy.

any reason why PHP upload script would work on PC but not Mac?

P: n/a
The following upload script seems to be working on PCs but not on
Macs. Can anyone imagine a reason why? Could there be something in the
form that turns in flawed data, or could IE on a Mac not pass along
certain data that Netscape and IE do on a PC?


function standardImageUpload() {
$controllerForAll = & getController();
$insertObject = & $controllerForAll->getObject("McTransactions", " in
standardImageUpload().");
$formatTextObject = & $controllerForAll->getObject("McFormatText", "
in standardImageUpload().");
$resultsObject = & $controllerForAll->getObject("McResults", " in
standardImageUpload().");

$config = getConfig();
$pathToImageFolder = $config["pathToImageFolder"];
$imagesFolder = $config["imagesFolder"];

global $uploadedFile, $uploadedFile_size, $uploadedFile_name;

if (!$uploadedFile) {
$uploadedFile = $controllerForAll->getVar("$uploadedFile");
$uploadedFile_size =
$controllerForAll->getVar("$uploadedFile_size");
$uploadedFile_size =
$controllerForAll->getVar("$uploadedFile_size");
}
$uploadedFile_name =
$formatTextObject->processFileName($uploadedFile_name);
$uploadedFile_name = htmlspecialchars($uploadedFile_name);
// 04-20-04 - we need to keep hackers from uploading files with PHP,
or if they do, we need to keep those files
// from being sent to the PHP parser. So we look for typical PHP
extensions.
$fileSafe = true;
$ext = substr($uploadedFile_name, -4);
if ($ext == "php3") $fileSafe = false;
if ($ext == ".php") $fileSafe = false;
if ($ext == ".inc") $fileSafe = false;
if ($ext == "phtm") $fileSafe = false;

$ext = substr($uploadedFile_name, -5);
if ($ext == "phtml") $fileSafe = false;
if ($fileSafe) {
$absolutePath .= $pathToImageFolder.$uploadedFile_name;
$urlPath .= $imagesFolder.$uploadedFile_name;

if (is_dir($pathToImageFolder)) {
if (!file_exists($absolutePath)) {
if (copy($uploadedFile, $absolutePath)) {
$resultsObject->addToResults("Success: The image or file
'$uploadedFile_name' has been uploaded. If you wish to reference it
this is the address: <a href='$urlPath'>$uploadedFile_name</a>");
} else {
if ($uploadedFile_size > 2000000) {
$resultsObject->addToResults("Error: the upload failed. Your
file of '$uploadedFile_name' is not uploaded. It is very large, with a
size of $uploadedFile_size. This may have been a factor in its
failure.");
} else {
$resultsObject->addToResults("Error: the upload failed. Your
file of '$uploadedFile_name' is not uploaded.");
}
}
} else {
$resultsObject->addToResults("Error: a file with the same name as
the one you are uploading already exists. Please delete the old file
first, and then upload the new one.");
}
} else {
$resultsObject->error("We tried to copy the image to the image
folder that is specified in your site's configuration, yet the folder
doesn't seem to be there.", "standardImageUpload");
}
$controllerForAll->import("standardInsert", " in
standardImageUpload().");
standardInsert();
} else {
$resultsObject->addToResults("<b>Error:</b> Terribly sorry, but it
looks like you're trying to upload a PHP file. For security reasons,
this is not allowed. The extension on your file was '$ext'.");
}
}
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 14 Jul 2004 23:15:51 -0700, lk******@geocities.com (lawrence)
wrote:
The following upload script seems to be working on PCs but not on
Macs. Can anyone imagine a reason why? Could there be something in the
form that turns in flawed data, or could IE on a Mac not pass along
certain data that Netscape and IE do on a PC?


the reason could be something in the form, but unfortunately I don't
see any <form> tag in your code ;-)

The most likely reason why forms do not work on some browsers is, that
you forgot to fill the "action" parameter in your form-tag correctly.
Some browsers (like IE on Windows) assume the same URL when this tag
is empty. But not all Browsers are so forgivable about that.

So it is obviously not a PHP problem, because PHP works regardless of
the browser type and OS because unlike JavaScript it runs on the
server, not in the browser.

Regards

Marian

--
Tipps und Tricks zu PHP, Coaching und Projektbetreuung
http://www.heddesheimer.de/coaching/
Jul 17 '05 #2

P: n/a
Marian Heddesheimer <10*************@spamgourmet.com> wrote in message news:<hv********************************@4ax.com>. ..
On 14 Jul 2004 23:15:51 -0700, lk******@geocities.com (lawrence)
wrote:
The following upload script seems to be working on PCs but not on
Macs. Can anyone imagine a reason why? Could there be something in the
form that turns in flawed data, or could IE on a Mac not pass along
certain data that Netscape and IE do on a PC?


the reason could be something in the form, but unfortunately I don't
see any <form> tag in your code ;-)

The most likely reason why forms do not work on some browsers is, that
you forgot to fill the "action" parameter in your form-tag correctly.
Some browsers (like IE on Windows) assume the same URL when this tag
is empty. But not all Browsers are so forgivable about that.

So it is obviously not a PHP problem, because PHP works regardless of
the browser type and OS because unlike JavaScript it runs on the
server, not in the browser.

Regards

Marian


Below you can see the entire form. Do you see something here that
would throw a flaw on a Mac?


<form method="post" action="/emt/mcControlPanel.php"
enctype="multipart/form-data" class="mcForm">
<input id="inputId1" type="hidden"
name="formInputs[formSecurityRating]" value="associate"
class="hiddenInput">

<script language="javascript">
function DoPreview()
{
var filename = document.forms[0].inputId1.value;
var Img = new Image();
if (navigator.appName == "Netscape")
{
alert("Previews do not work in Netscape.");
}
else
{
Img.src = filename;
ppImg = Img.src;
alert("You're loading image" + ppImg);
document.images[0].src = Img.src;
}
}
</script>

<div class="formElement">

Upload an image:
<input type="file" name="uploadedFile"><input type="hidden"
name="uploadType" value="image" onchange="DoPreview();"></div>

<div class="formElement">
Type an easy to read name (as opposed to the file name) for this
image:
<div class="inputBoxTitle"><input id="inputId2" type="text"
name="formInputs[cbHeadline]" value="" class="textInput">
</div></div>

<div class="formElement">
Type a brief description:<br>
<textarea id="inputId3" name="formInputs[cbMainContent]"
class="textareaInput"></textarea>

</div>

<div class="formElement">
Assign a category:
<select id="publicpenFormInput4" name="formInputs[cbModifier25]">
<option value=""></option>
<option value="x#x#x#blankx#x#x#">No choice made</option>
<option value="oil">oil</option>
<option value="painting">painting</option>

<option value="PREWRITES">PREWRITES</option>
<option value="watercolor">watercolor</option>
</select>

<br>
Assign a category:
<select id="publicpenFormInput5" name="formInputs[cbModifier26]">
<option value=""></option>
<option value="x#x#x#blankx#x#x#">No choice made</option>

<option value="oil">oil</option>
<option value="painting">painting</option>
<option value="PREWRITES">PREWRITES</option>
<option value="watercolor">watercolor</option>
</select>

<br>
Assign a category:
<select id="publicpenFormInput6" name="formInputs[cbModifier27]">
<option value=""></option>
<option value="x#x#x#blankx#x#x#">No choice made</option>
<option value="oil">oil</option>
<option value="painting">painting</option>
<option value="PREWRITES">PREWRITES</option>

<option value="watercolor">watercolor</option>
</select>

<br>
Assign a category:
<select id="publicpenFormInput7" name="formInputs[cbModifier28]">
<option value=""></option>
<option value="x#x#x#blankx#x#x#">No choice made</option>
<option value="oil">oil</option>

<option value="painting">painting</option>
<option value="PREWRITES">PREWRITES</option>
<option value="watercolor">watercolor</option>
</select>

<br>
Assign a category:
<select id="publicpenFormInput8" name="formInputs[cbModifier29]">

<option value=""></option>
<option value="x#x#x#blankx#x#x#">No choice made</option>
<option value="oil">oil</option>
<option value="painting">painting</option>
<option value="PREWRITES">PREWRITES</option>
<option value="watercolor">watercolor</option>

</select>

<br>
Assign a category:
<select id="publicpenFormInput9" name="formInputs[cbModifier30]">
<option value=""></option>
<option value="x#x#x#blankx#x#x#">No choice made</option>
<option value="oil">oil</option>
<option value="painting">painting</option>

<option value="PREWRITES">PREWRITES</option>
<option value="watercolor">watercolor</option>
</select>


</div>
<input type="hidden" name="formInputs[cbWhichType]" value="imageInfo">

<input type="hidden" name="choiceMade" value="standardImageUpload">
<input type="hidden" name="actions[choiceMade]"
value="standardImageUpload">
<input type="hidden" name="fileName" value="">
<input type="submit" value="Click here when done" class="submitInput">
</form>
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.