473,714 Members | 2,340 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

chmod to 777 but still get permission denied on image upload

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>
&lt;img src='$imagesFol der'&gt;
<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 &lt;img src='myImage.jp g'
ALT='Photo taken in downtown Charlottesville '&gt; 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 &lt;center&g t; before it and the tag
&lt;/center&gt; 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();

}
Jul 16 '05 #1
15 12013
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($uploaded File, $pathToImageFol der)){


Try using move_uploaded_f ile and $_FILES :-)

--
Christian Jørgensen | It's so complicated, it can't crash.
http://www.razor.dk |

Jul 16 '05 #2
Christian Joergensen <ma**@phpguru.d k> 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($uploaded File, $pathToImageFol der)){


Try using move_uploaded_f ile 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_f ile, which
worked fine till I uploaded the software to a machine running
something like version 4.0.1 of PHP.
Jul 16 '05 #3
lk******@geocit ies.com (lawrence) wrote in message news:<da******* *************** ****@posting.go ogle.com>...
Christian Joergensen <ma**@phpguru.d k> 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($uploaded File, $pathToImageFol der)){


Try using move_uploaded_f ile 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_f ile, 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?
Jul 16 '05 #4
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******@geocit ies.com (lawrence) wrote in message news:<da******* *************** ****@posting.go ogle.com>...
Christian Joergensen <ma**@phpguru.d k> 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($uploaded File, $pathToImageFol der)){

Try using move_uploaded_f ile 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_f ile, 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?


Jul 16 '05 #5
lawrence wrote:
haptiK <ha****@yahoo.c om> wrote in message
news:<bh******* ***@hercules.bt internet.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($uploaded File, $pathToImageFol der)){


well, you might want to try using the $_FILES['uploadedFile'] array -
have a look at the PHP manual under "Handling file uploads"

Matt
Jul 16 '05 #6
matty <ma*******@askm enoquestions.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($uploaded File, $pathToImageFol der)){


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
Jul 16 '05 #7
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******@geocit ies.com (lawrence) wrote in message
news:<da******* *************** ****@posting.go ogle.com>...
matty <ma*******@askm enoquestions.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($uploaded File, $pathToImageFol der)){


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

Jul 16 '05 #8
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******@geocit ies.com (lawrence) wrote in message news:<da******* *************** ****@posting.go ogle.com>...
matty <ma*******@askm enoquestions.co .uk> wrote in message news:<GC******* ************@wa rds.force9.net> ...
lawrence wrote:
haptiK <ha****@yahoo.c om> wrote in message
news:<bh******* ***@hercules.bt internet.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($uploaded File, $pathToImageFol der)){


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="multip art/form-data"
action="/admin/mcFlashGalleryC ontrolPanel.php ?choiceMade=ins ertAndUploadNew Item"
method="POST">

<div id="mcFormBlock 0" class="mcFormBl ock">
Title<br>
<input id="inputId0" type="text" name="title" value=""
class="textInpu t">

</div>
<div id="mcFormBlock 2" class="mcFormBl ock">
File<br>
<input id="inputId2" type="text" name="file" value=""
class="textInpu t">

</div>
<div id="mcFormBlock 4" class="mcFormBl ock">
Dimensions<br>
<input id="inputId4" type="text" name="dimension s" value=""
class="textInpu t">

</div>
<div id="mcFormBlock 6" class="mcFormBl ock">
Price<br>
<input id="inputId6" type="text" name="price" value=""
class="textInpu t">

</div>

<span class="formText ">This is your current category: No category
chosen yet. </span>
<div id="mcFormBlock 9" class="mcFormBl ock">
Choose a category <select id="inputId9" name="category" > <option
value="false">N o category chosen yet</option> <option
value="water">w ater</option> <option
value="drawings ">drawings</option> <option
value="other">o ther</option><option value="photos"> photos</option>
<option value="oil">oil </option> </select>
</div>
<div id="mcFormBlock 11" class="mcFormBl ock">
Description<br>
<textarea id="inputId11" name="descripti on" rows="14" cols="50"
class="textarea Input"></textarea>

</div>

<td> <input type="hidden" name="MAX_FILE_ SIZE" value="10000000 ">
Upload this file:
<input name="userfile" type="file"><in put type="submit"></form>



function insertAndUpload NewItem() {
// $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
printFormForIns ertAndUploadNew Item() - 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_nam e." ".$userfile_siz e."
".$userfile_typ e."<br>";

if ($userfile=="no ne"){
$results .= "Problem: no file uploaded";
}

if ($userfile_size ==0){
$results .= "Problem: uploaded file is zero length";
}

$upfile = $filepath.$user file_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($tit le);
$file = addslashes($fil e);
$dimensions = addslashes($dim ensions);
$price = addslashes($pri ce);
$description = addslashes($des cription);
$catagory = addslashes($cat egory);

$query = "INSERT INTO products VALUES(NULL, '".$title."' ,
'".$file."', '".$dimensions. "', '".$price."' , '".$description ."', '".$catagory."' )";
echo "<hr>here's the query: $query <hr>";
$result = $db->query($query );
$numOfRowsAffec ted = $db->rows();
if($result) $results .= "$numOfRowsAffe cted row inserted into
database.";

// 08-19-03 - every function that does something should end by
posting the results to the screen. - lk
echo $results;
}

Jul 16 '05 #9
we***********@y ahoo.com (Wes Bailey) wrote in message news:<c3******* *************** ***@posting.goo gle.com>...
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.)
Jul 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
16812
by: Daniel | last post by:
Hi, From what I read from the PHP manual, chmod on a Windows platform should have no effect, and that seems totally normal (unless someone on sourceforge has a windows port of that!). I create a directory on my Windows box, and set chmod 777 on it (that should be full access for everyone if my memory serves me correctly), but when I want to rmdir that directory, I get a permission denied message (I can delete contents from that...
4
4830
by: Ian N | last post by:
Hi i'm having a problem with file permissions of upload, they appear to be being set to only readable by the administrator, so anyone browsing the site gets a 403 forbidden error when they try and view the image. I've tried adding the following line: - chmod($uploadfile, 444); and also a few variations on it but to no avail.
6
1526
by: Andy | last post by:
Hi I have created a facility to allow the user to upload an image file to the webserver. When the user creates the image for the first time i.e. the image does not exist within the directory everything works fine. The problem occurs if my ASP.NET dll tries to delete the file or overwrite it??? I assume my app will be using the ASPNET account and I
47
3313
by: frizzle | last post by:
Hi, I am at the base of an FTP thingy i'm building, and i noticed that it would only work if i chmod the folder 777, i thought to remember correctly that previously on another site chmod 744 was enough, now it isn't. Am i mistaking, and should it always be 777 ? And isn't a chmodded 777 folder much more vulnerable? Frizzle.
3
4764
by: Rik | last post by:
Hello, first of all, my provider sucks, newsserver is down for the #nth time now, offcourse when I have an urgent question.... So this will be me first time using Google Groups, forgive me if something goes wrong. The problem at hand: In a restricted area I let a user upload an image, no problem The image gets scaled down with imagecopyresampled(), and stored with imagejpeg($resized_img,'/path/to/target/image.jpg')
0
1781
by: foekall | last post by:
I used this script and test on my hosting. Evertimes appear "change permission to 777 failed. ". So, how to solve this error. Please kindly check for me and teach me. <?php $MAX_SIZE = 2000000;
0
8802
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9017
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5948
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4726
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3158
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.