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($uploadedFile, $pathToImageFolder)){
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_size, $uploadedFile_name, $overRide;
$uploadedFile_name = processFileName($uploadedFile_name);
$uploadedFile_name = htmlspecialchars($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='dvclMcWholeForm'>
<form method='post' action='$self' enctype='multipart/form-data'
class='mcForm'>
Upload this image: <br>
<input type='file' name='uploadedFile'><br><br>
<input type='hidden' name='choiceMade' value='uploadImage'>
<input type='hidden' name='overRide' value='true'>
<input type='submit' value='Upload File'>
</form>
</div>
";
endPage();
} else {
$pathToImageFolder .= $uploadedFile_name;
$imagesFolder .= $uploadedFile_name;
echo "<br><br><br><br> here's the file name $uploadedFile_name and
here's the folder $pathToImageFolder ";
if (copy($uploadedFile, $pathToImageFolder)) {
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='$imagesFolder'>
$imagesFolder
</a>
<BR><BR>
The code for a link to this image would look like this:<br><br>
<img src='$imagesFolder'>
<br><br>
Put this code on any page where you want this image to appear:
<br><br>
<img src='$imagesFolder'>
<br><br>
The ALT tag controls what text appears when the mouse cursor hovers
over an image. If you type <img src='myImage.jpg'
ALT='Photo taken in downtown Charlottesville'> then the words
'Photo taken in downtown Charlottesville' are what appear.
<a href='http://www.htmlhelp.com/reference/wilbur/syntax.html'>You
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> 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 printFormForImageUpload() {
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='dvclMcWholeForm'>
<form method='post' action='$self' enctype='multipart/form-data'
class='mcForm'>
Upload this image: <br>
<input type='file' name='uploadedFile'><br><br>
<input type='hidden' name='choiceMade' value='uploadImage'>
<input type='submit' value='Upload File'>
</div>
";
endPage();
} 15 11867
On Sat, 09 Aug 2003 22:47:54 -0700, lawrence wrote: 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($uploadedFile, $pathToImageFolder)){
Try using move_uploaded_file and $_FILES :-)
--
Christian Jørgensen | It's so complicated, it can't crash. http://www.razor.dk |
Christian Joergensen <ma**@phpguru.dk> wrote in message news:<pa****************************@razor.dk>... On Sat, 09 Aug 2003 22:47:54 -0700, lawrence wrote:
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($uploadedFile, $pathToImageFolder)){
Try using move_uploaded_file and $_FILES :-)
Aren't those new? The code I'm writing needs to run on all kinds of
machines, some of which will be running old versions of PHP. As I
recall, a year ago I changed the code to use move_uploaded_file, which
worked fine till I uploaded the software to a machine running
something like version 4.0.1 of PHP. lk******@geocities.com (lawrence) wrote in message news:<da**************************@posting.google. com>... Christian Joergensen <ma**@phpguru.dk> wrote in message news:<pa****************************@razor.dk>... On Sat, 09 Aug 2003 22:47:54 -0700, lawrence wrote:
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($uploadedFile, $pathToImageFolder)){
Try using move_uploaded_file and $_FILES :-)
Aren't those new? The code I'm writing needs to run on all kinds of machines, some of which will be running old versions of PHP. As I recall, a year ago I changed the code to use move_uploaded_file, which worked fine till I uploaded the software to a machine running something like version 4.0.1 of PHP.
Can anyone think of any non-permission errors?
what is the exact error you are recieving and what version of php are
you running. this information is vital to providing the solution.
- jpdr
TTG
lawrence wrote: lk******@geocities.com (lawrence) wrote in message news:<da**************************@posting.google. com>...
Christian Joergensen <ma**@phpguru.dk> wrote in message news:<pa****************************@razor.dk>...
On Sat, 09 Aug 2003 22:47:54 -0700, lawrence wrote:
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($uploadedFile, $pathToImageFolder)){
Try using move_uploaded_file and $_FILES :-)
Aren't those new? The code I'm writing needs to run on all kinds of machines, some of which will be running old versions of PHP. As I recall, a year ago I changed the code to use move_uploaded_file, which worked fine till I uploaded the software to a machine running something like version 4.0.1 of PHP.
Can anyone think of any non-permission errors?
lawrence wrote: haptiK <ha****@yahoo.com> wrote in message news:<bh**********@hercules.btinternet.com>... what is the exact error you are recieving and what version of php are you running. this information is vital to providing the solution.
- jpdr TTG
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($uploadedFile, $pathToImageFolder)){
well, you might want to try using the $_FILES['uploadedFile'] array -
have a look at the PHP manual under "Handling file uploads"
Matt
matty <ma*******@askmenoquestions.co.uk> wrote in message 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($uploadedFile, $pathToImageFolder)){
well, you might want to try using the $_FILES['uploadedFile'] array - have a look at the PHP manual under "Handling file uploads"
Matt
As mentioned before, I'm trying to remain backward compatible to PHP
4.0.3, if possible. But lets assume for a moment that backwards
compatibility is not an issue. Why do you want me to use $_FILES? Did
you see a place where I failed to account for the scope of a variable?
If so, please let me know.
-- lawrence
Maybe a silly question now but did you check the ownership of the
directory you are writing too? if the web server (usually setup as
nobody:nogroup) doesn't own the directory or isn't part of a group
that has access, you won't be able to access the files regardless of
their permission.
Wes lk******@geocities.com (lawrence) wrote in message news:<da**************************@posting.google. com>... matty <ma*******@askmenoquestions.co.uk> wrote in message 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($uploadedFile, $pathToImageFolder)){
well, you might want to try using the $_FILES['uploadedFile'] array - have a look at the PHP manual under "Handling file uploads"
Matt
As mentioned before, I'm trying to remain backward compatible to PHP 4.0.3, if possible. But lets assume for a moment that backwards compatibility is not an issue. Why do you want me to use $_FILES? Did you see a place where I failed to account for the scope of a variable? If so, please let me know.
-- lawrence
Let me put the question another way. When you upload the file, you can
treat it as an array variable like any other? If I say:
global $userfile;
then it is within scope inside of the function, yes?? lk******@geocities.com (lawrence) wrote in message news:<da**************************@posting.google. com>... matty <ma*******@askmenoquestions.co.uk> wrote in message news:<GC*******************@wards.force9.net>... lawrence wrote:
haptiK <ha****@yahoo.com> wrote in message news:<bh**********@hercules.btinternet.com>... > what is the exact error you are recieving and what version of php are > you running. this information is vital to providing the solution. > > - jpdr > TTG
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($uploadedFile, $pathToImageFolder)){
well, you might want to try using the $_FILES['uploadedFile'] array - have a look at the PHP manual under "Handling file uploads"
Matt
I wrote a different script today, I was rewriting another programmers code, but ran into the same problem as before. All this code is being executed on the same server, though for different web sites. This line dies:
if (!move_uploaded_file($userfile, $upfile)) {
In this case it seems like I don't have $userfile. The variable seems empty. This is the form in use, and the function which receives it:
<form enctype="multipart/form-data" action="/admin/mcFlashGalleryControlPanel.php?choiceMade=insertAn dUploadNewItem" method="POST">
<div id="mcFormBlock0" class="mcFormBlock"> Title<br> <input id="inputId0" type="text" name="title" value="" class="textInput">
</div>
<div id="mcFormBlock2" class="mcFormBlock"> File<br> <input id="inputId2" type="text" name="file" value="" class="textInput">
</div>
<div id="mcFormBlock4" class="mcFormBlock"> Dimensions<br> <input id="inputId4" type="text" name="dimensions" value="" class="textInput">
</div>
<div id="mcFormBlock6" class="mcFormBlock"> Price<br> <input id="inputId6" type="text" name="price" value="" class="textInput">
</div>
<span class="formText">This is your current category: No category chosen yet. </span> <div id="mcFormBlock9" class="mcFormBlock"> Choose a category <select id="inputId9" name="category"> <option value="false">No category chosen yet</option> <option value="water">water</option> <option value="drawings">drawings</option> <option value="other">other</option><option value="photos">photos</option> <option value="oil">oil</option> </select> </div>
<div id="mcFormBlock11" class="mcFormBlock"> Description<br> <textarea id="inputId11" name="description" rows="14" cols="50" class="textareaInput"></textarea>
</div>
<td> <input type="hidden" name="MAX_FILE_SIZE" value="10000000"> Upload this file: <input name="userfile" type="file"><input type="submit"></form> function insertAndUploadNewItem() { // $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
// 08-19-03 - this is receiving the input from printFormForInsertAndUploadNewItem() - lk // $file or $userfile is the name of the file being uploaded, $filepath is from the config file, we get it so we know where to store // the file that just got uploaded. global $userfile, $filepath; global $db, $title, $file, $dimensions, $price, $description, $category;
$results = "";
$results .="Variables are:<br>"; $results .= $userfile." ".$userfile_name." ".$userfile_size." ".$userfile_type."<br>";
if ($userfile=="none"){ $results .= "Problem: no file uploaded"; }
if ($userfile_size==0){ $results .= "Problem: uploaded file is zero length"; }
$upfile = $filepath.$userfile_name; echo $results; if (!move_uploaded_file($userfile, $upfile)) { $results .= "Problem: Could not move file into directory"; } else { $results .= "File uploaded successfully<br><br>"; }
$title = addslashes($title); $file = addslashes($file); $dimensions = addslashes($dimensions); $price = addslashes($price); $description = addslashes($description); $catagory = addslashes($category);
$query = "INSERT INTO products VALUES(NULL, '".$title."', '".$file."', '".$dimensions."', '".$price."', '".$description."', '".$catagory."')"; echo "<hr>here's the query: $query <hr>"; $result = $db->query($query); $numOfRowsAffected = $db->rows(); if($result) $results .= "$numOfRowsAffected row inserted into database.";
// 08-19-03 - every function that does something should end by posting the results to the screen. - lk echo $results; } we***********@yahoo.com (Wes Bailey) wrote in message news:<c3*************************@posting.google.c om>... Maybe a silly question now but did you check the ownership of the directory you are writing too? if the web server (usually setup as nobody:nogroup) doesn't own the directory or isn't part of a group that has access, you won't be able to access the files regardless of their permission.
That's a good question. I think I logged in with FTP, using a username
and password that wasn't root but had root level access. (The server
is aware of some "super-super-root" user that we try to never use. I
think there are 3 of us with normal root level access to the server.)
If copy() fails, what reasons can it fail, other than permissions? lk******@geocities.com (lawrence) wrote in message news:<da**************************@posting.google. com>... 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($uploadedFile, $pathToImageFolder)){
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_size, $uploadedFile_name, $overRide; $uploadedFile_name = processFileName($uploadedFile_name); $uploadedFile_name = htmlspecialchars($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='dvclMcWholeForm'>
<form method='post' action='$self' enctype='multipart/form-data' class='mcForm'> Upload this image: <br> <input type='file' name='uploadedFile'><br><br> <input type='hidden' name='choiceMade' value='uploadImage'> <input type='hidden' name='overRide' value='true'> <input type='submit' value='Upload File'> </form> </div> "; endPage(); } else { $pathToImageFolder .= $uploadedFile_name; $imagesFolder .= $uploadedFile_name; echo "<br><br><br><br> here's the file name $uploadedFile_name and here's the folder $pathToImageFolder ";
if (copy($uploadedFile, $pathToImageFolder)) {
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='$imagesFolder'> $imagesFolder </a> <BR><BR> The code for a link to this image would look like this:<br><br> <img src='$imagesFolder'> <br><br> Put this code on any page where you want this image to appear: <br><br> <img src='$imagesFolder'> <br><br> The ALT tag controls what text appears when the mouse cursor hovers over an image. If you type <img src='myImage.jpg' ALT='Photo taken in downtown Charlottesville'> then the words 'Photo taken in downtown Charlottesville' are what appear. <a href='http://www.htmlhelp.com/reference/wilbur/syntax.html'>You 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> 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 printFormForImageUpload() { 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='dvclMcWholeForm'> <form method='post' action='$self' enctype='multipart/form-data' class='mcForm'> Upload this image: <br> <input type='file' name='uploadedFile'><br><br> <input type='hidden' name='choiceMade' value='uploadImage'> <input type='submit' value='Upload File'> </div> "; endPage();
}
On 31 Aug 2003 16:30:41 -0700, lawrence hath writ: If copy() fails, what reasons can it fail, other than permissions?
Even tho' you top-posted - and did not trim...
Have you check permissions on the *directory* ?
Jonesy
--
| Marvin L Jones | jonz | W3DHJ | OS/2
| Gunnison, Colorado | @ | Jonesy | linux __
| 7,703' -- 2,345m | config.com | DM68mn SK
lawrence wrote: if (copy($uploadedFile, $pathToImageFolder)){
This is the error I get:
Warning: Unable to access in /home/www/krubner/atp/mcIncludes/mcImages.php on line 199
Your error is here. standard form of this error message is
Warning: unable to access /var/files/foo/bar in
....
Chances are, the variable you're using for the filename is
empty. Are you using $_FILES, or are you using an old,
register_globals on style variable?
Allodoxaphobia <bi********@config.com> wrote in message news:<sl***********************@localhost.config.c om>... On 31 Aug 2003 16:30:41 -0700, lawrence hath writ: If copy() fails, what reasons can it fail, other than permissions?
Even tho' you top-posted - and did not trim...
Have you check permissions on the *directory* ?
Jonesy
Thanks, but yes, we checked permissions on the directory many times.
matty <ma*******@askmenoquestions.co.uk> wrote in message news:<3O*******************@wards.force9.net>... lawrence wrote:
if (copy($uploadedFile, $pathToImageFolder)){
This is the error I get:
Warning: Unable to access in /home/www/krubner/atp/mcIncludes/mcImages.php on line 199
Your error is here. standard form of this error message is
Warning: unable to access /var/files/foo/bar in ...
Chances are, the variable you're using for the filename is empty. Are you using $_FILES, or are you using an old, register_globals on style variable?
I'm not sure why you're asking since you can see all my code. The
variable seems to be empty but note these lines:
global $userfile, $filepath; global $db, $title, $file, $dimensions, $price, $description, $category;
Earlier in this thread someone asked if I was using $_FILES and I
explained I wasn't because we were trying to stay backwards compatible
with PHP 4.01. However, as I recall, sometime last month I did switch
over and use $_FILES just to see if it would help. It didn't.
lawrence wrote: matty <ma*******@askmenoquestions.co.uk> wrote in message news:<3O*******************@wards.force9.net>... lawrence wrote:
>> >> if (copy($uploadedFile, $pathToImageFolder)){ >> >> >> This is the error I get: >> >> Warning: Unable to access in >> /home/www/krubner/atp/mcIncludes/mcImages.php on line 199 >> >>
Your error is here. standard form of this error message is
Warning: unable to access /var/files/foo/bar in ...
Chances are, the variable you're using for the filename is empty. Are you using $_FILES, or are you using an old, register_globals on style variable?
I'm not sure why you're asking since you can see all my code. The variable seems to be empty but note these lines:
global $userfile, $filepath; global $db, $title, $file, $dimensions, $price, $description, $category;
Earlier in this thread someone asked if I was using $_FILES and I explained I wasn't because we were trying to stay backwards compatible with PHP 4.01. However, as I recall, sometime last month I did switch over and use $_FILES just to see if it would help. It didn't.
you'll need to turn registerr_globals on, but bear in mind that making
your script compatible with old php versions will make it incompatible
with 80% of the webservers out there. There aren't that many running < 4.2 nowadays This discussion thread is closed Replies have been disabled for this discussion. Similar topics
5 posts
views
Thread by Daniel |
last post: by
|
4 posts
views
Thread by Ian N |
last post: by
|
6 posts
views
Thread by Andy |
last post: by
|
47 posts
views
Thread by frizzle |
last post: by
|
3 posts
views
Thread by Rik |
last post: by
| | | | | | | | | | | |