I've been using the following function (yes, it is inelegant, what can
I say, I wrote it a long time ago) to upload images. Haven't had a
problem with it for at least a year, and I don't recall changing it
anytime recently. Nevertheless, the script is suddenly dying on this
line:
if (copy($uploaded File, $pathToImageFol der)){
This is the error I get:
Warning: Unable to access in
/home/www/krubner/atp/mcIncludes/mcImages.php on line 199
My first thought was to check permissions - they were set to 755, but
to test if they were the problem I changed them to 777. Tried again
and got the same problem. So then I added in the line, you'll see it
below, where I try to echo out the values. This is what I get:
here's the file name and here's the folder
/home/krubner/www/atp/mcImages/
There is no file name. I assume that is the problem, but why is there
suddenly no file name? (I'm running version 4.2.3 of PHP, if you're
asking).
function uploadImage() {
extract($config = getConfig());
global $forms, $io, $users, $links, $sql, $uploadedFile,
$uploadedFile_s ize, $uploadedFile_n ame, $overRide;
$uploadedFile_n ame = processFileName ($uploadedFile_ name);
$uploadedFile_n ame = htmlspecialchar s($uploadedFile _name);
if ($uploadedFile_ size > 10000000 && $overRide != "true") {
startPage("This image is very large, over 10 megabyte. Are you sure
you want to proceed?");
echo "
<div class='dvclMcWh oleForm'>
<form method='post' action='$self' enctype='multip art/form-data'
class='mcForm'>
Upload this image: <br>
<input type='file' name='uploadedF ile'><br><br>
<input type='hidden' name='choiceMad e' value='uploadIm age'>
<input type='hidden' name='overRide' value='true'>
<input type='submit' value='Upload File'>
</form>
</div>
";
endPage();
} else {
$pathToImageFol der .= $uploadedFile_n ame;
$imagesFolder .= $uploadedFile_n ame;
echo "<br><br><br><b r> here's the file name $uploadedFile_n ame and
here's the folder $pathToImageFol der ";
if (copy($uploaded File, $pathToImageFol der)) {
startPage();
echo "
<div class='mcForm'>
The image or file has been uploaded. If you wish to reference it
this is the address:<br><br >
<a href='$imagesFo lder'>
$imagesFolder
</a>
<BR><BR>
The code for a link to this image would look like this:<br><br>
<img src='$imagesFol der'>
<br><br>
Put this code on any page where you want this image to appear:
<br><br>
<img src='$imagesFol der'>
<br><br>
The ALT tag controls what text appears when the mouse cursor hovers
over an image. If you type <img src='myImage.jp g'
ALT='Photo taken in downtown Charlottesville '> then the words
'Photo taken in downtown Charlottesville ' are what appear.
<a href='http://www.htmlhelp.co m/reference/wilbur/syntax.html'>Yo u
can read more about IMG tag syntax on htmlHelp.com</a>
<br><br>
Also note that if you want an image to float in the middle of a
column, just put the tag <center&g t; before it and the tag
</center> after it. (Hopefully all this code writing will be
automated in future versions of this software; for now,
sorry folks, but you've got to hand edit these tags if you want
them any different than how they are listed below.)
</div>
";
endPage();
} else {
global $forms, $io, $users, $links, $sql, $users;
startPage();
echo "
<div class='mcForm'>
For some reason the upload failed. This problem might be temporary
or permanent. Try again.
</div>
";
endPage();
}
}
}
function printFormForIma geUpload() {
extract($config = getConfig());
// We need to print the form
startPage("Note : certain image types don't work on the web. Upload
images that have 'jpe' or 'jpg' or 'jpeg' or 'gif' or 'png' as their
endings.");
echo "
<div class='dvclMcWh oleForm'>
<form method='post' action='$self' enctype='multip art/form-data'
class='mcForm'>
Upload this image: <br>
<input type='file' name='uploadedF ile'><br><br>
<input type='hidden' name='choiceMad e' value='uploadIm age'>
<input type='submit' value='Upload File'>
</div>
";
endPage();
}
I say, I wrote it a long time ago) to upload images. Haven't had a
problem with it for at least a year, and I don't recall changing it
anytime recently. Nevertheless, the script is suddenly dying on this
line:
if (copy($uploaded File, $pathToImageFol der)){
This is the error I get:
Warning: Unable to access in
/home/www/krubner/atp/mcIncludes/mcImages.php on line 199
My first thought was to check permissions - they were set to 755, but
to test if they were the problem I changed them to 777. Tried again
and got the same problem. So then I added in the line, you'll see it
below, where I try to echo out the values. This is what I get:
here's the file name and here's the folder
/home/krubner/www/atp/mcImages/
There is no file name. I assume that is the problem, but why is there
suddenly no file name? (I'm running version 4.2.3 of PHP, if you're
asking).
function uploadImage() {
extract($config = getConfig());
global $forms, $io, $users, $links, $sql, $uploadedFile,
$uploadedFile_s ize, $uploadedFile_n ame, $overRide;
$uploadedFile_n ame = processFileName ($uploadedFile_ name);
$uploadedFile_n ame = htmlspecialchar s($uploadedFile _name);
if ($uploadedFile_ size > 10000000 && $overRide != "true") {
startPage("This image is very large, over 10 megabyte. Are you sure
you want to proceed?");
echo "
<div class='dvclMcWh oleForm'>
<form method='post' action='$self' enctype='multip art/form-data'
class='mcForm'>
Upload this image: <br>
<input type='file' name='uploadedF ile'><br><br>
<input type='hidden' name='choiceMad e' value='uploadIm age'>
<input type='hidden' name='overRide' value='true'>
<input type='submit' value='Upload File'>
</form>
</div>
";
endPage();
} else {
$pathToImageFol der .= $uploadedFile_n ame;
$imagesFolder .= $uploadedFile_n ame;
echo "<br><br><br><b r> here's the file name $uploadedFile_n ame and
here's the folder $pathToImageFol der ";
if (copy($uploaded File, $pathToImageFol der)) {
startPage();
echo "
<div class='mcForm'>
The image or file has been uploaded. If you wish to reference it
this is the address:<br><br >
<a href='$imagesFo lder'>
$imagesFolder
</a>
<BR><BR>
The code for a link to this image would look like this:<br><br>
<img src='$imagesFol der'>
<br><br>
Put this code on any page where you want this image to appear:
<br><br>
<img src='$imagesFol der'>
<br><br>
The ALT tag controls what text appears when the mouse cursor hovers
over an image. If you type <img src='myImage.jp g'
ALT='Photo taken in downtown Charlottesville '> then the words
'Photo taken in downtown Charlottesville ' are what appear.
<a href='http://www.htmlhelp.co m/reference/wilbur/syntax.html'>Yo u
can read more about IMG tag syntax on htmlHelp.com</a>
<br><br>
Also note that if you want an image to float in the middle of a
column, just put the tag <center&g t; before it and the tag
</center> after it. (Hopefully all this code writing will be
automated in future versions of this software; for now,
sorry folks, but you've got to hand edit these tags if you want
them any different than how they are listed below.)
</div>
";
endPage();
} else {
global $forms, $io, $users, $links, $sql, $users;
startPage();
echo "
<div class='mcForm'>
For some reason the upload failed. This problem might be temporary
or permanent. Try again.
</div>
";
endPage();
}
}
}
function printFormForIma geUpload() {
extract($config = getConfig());
// We need to print the form
startPage("Note : certain image types don't work on the web. Upload
images that have 'jpe' or 'jpg' or 'jpeg' or 'gif' or 'png' as their
endings.");
echo "
<div class='dvclMcWh oleForm'>
<form method='post' action='$self' enctype='multip art/form-data'
class='mcForm'>
Upload this image: <br>
<input type='file' name='uploadedF ile'><br><br>
<input type='hidden' name='choiceMad e' value='uploadIm age'>
<input type='submit' value='Upload File'>
</div>
";
endPage();
}
Comment