473,836 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Chmod

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.
Code sofar below:
+++++++++++++++ +++++++++++
<?php

require_once('. ./inc/globals.php');

if( isset( $_FILES['image'] ) ){

$ftp_conn = @ftp_connect( $default_ftp_se rver )or
die('<b>Error!</b>');
@ftp_login( $ftp_conn, $default_ftp_us er, $default_ftp_pa ss )or
die('<bError!</b>');

$uploaddir = '../items/';
$uploadfile = $uploaddir . basename( $_FILES['image']['name'] );

if ( move_uploaded_f ile( $_FILES['image']['tmp_name'], $uploadfile ) ){
echo "File is valid, and was successfully uploaded.";
} else {
echo "Possible file upload attack!";
};

ftp_close( $ftp_conn );

};

?>
<form action="<?php echo $PHP_SELF; ?>" method="post"
enctype="multip art/form-data" name="images" target="_top" id="images"
class="form">
<input name="image" type="file" id="image">
<br>
<input type="submit" name="upload" id="upload" value="Upload">
<input name="cancel" type="button" id="cancel" value="Cancel"
onClick="javasc ript:history.go (-1) ">
</form><?php

if (is_dir($upload dir)) {
if ($dh = opendir($upload dir)) {
while (($file = readdir($dh)) !== false) {
if ($file !== '..' && $file !== '.') echo "filename: $file :
filetype: " . filetype($uploa ddir . $file) . "<br>\r\n";
}
closedir($dh);
}
};

?>
----------------------------------------------------

Apr 4 '06
47 3347
Jerry Stuckle wrote:
frizzle wrote:
I asked my webhost, but they told me uploading
a folder and having it running uploads etc. is not
possible on Linux by default. Folders should be
chmod 777 or chmod 755.

Frizzle.


Yes and no. It depends on how they have their folders configured.

However, obviously they have it configured so you can't do it. But you should
still be able to create the folder in PHP from a web page (so it's running as
the Apache user) and upload to it. The folder should then have the Apache user
as the owner.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===


AFAIK the script below should be able to create dirs then
but i get the following error:

Warning: mkdir(testdir): Permission denied in
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 5

Warning: Cannot modify header information - headers already sent by
(output started at
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php:5) in
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 6

Frizzle.

+++++++++++++++ +++++++++++++++ +++++++++++++++ ++++++

<?php

if(isset( $_POST['dir'] ))
{
mkdir( $_POST['dir'], 0755 );
header('Locatio n: '.$PHP_SELF);
};
?><form action="<?php echo $PHP_SELF; ?>" method="post"
name="mkdirtest " target="_top" id="mkdirtest" >
<label for="dir">dir</label>
<input type="text" name="dir" id="dir"<?php echo isset( $_POST['dir']
) ? ' value="'.$_POST['dir'].'"' : '' ?>>
<label for="Submit"></label>
<input type="submit" name="Submit" value="mkdir!" id="Submit">
</form><?php

$handle = opendir('.');

while (false !== ($file = readdir($handle ))) {
if ($file != "." && $file != ".." ) {
echo $file.'<br>';
};
};

closedir( $handle );

?>

Apr 14 '06 #31
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
I asked my webhost, but they told me uploading
a folder and having it running uploads etc. is not
possible on Linux by default. Folders should be
chmod 777 or chmod 755.

Frizzle.


Yes and no. It depends on how they have their folders configured.

However, obviously they have it configured so you can't do it. But you should
still be able to create the folder in PHP from a web page (so it's running as
the Apache user) and upload to it. The folder should then have the Apache user
as the owner.

--
============= =====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@att global.net
============= =====

AFAIK the script below should be able to create dirs then
but i get the following error:

Warning: mkdir(testdir): Permission denied in
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 5

Warning: Cannot modify header information - headers already sent by
(output started at
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php:5) in
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 6

Frizzle.

+++++++++++++++ +++++++++++++++ +++++++++++++++ ++++++

<?php

if(isset( $_POST['dir'] ))
{
mkdir( $_POST['dir'], 0755 );
header('Locatio n: '.$PHP_SELF);
};
?><form action="<?php echo $PHP_SELF; ?>" method="post"
name="mkdirtest " target="_top" id="mkdirtest" >
<label for="dir">dir</label>
<input type="text" name="dir" id="dir"<?php echo isset( $_POST['dir']
) ? ' value="'.$_POST['dir'].'"' : '' ?>>
<label for="Submit"></label>
<input type="submit" name="Submit" value="mkdir!" id="Submit">
</form><?php

$handle = opendir('.');

while (false !== ($file = readdir($handle ))) {
if ($file != "." && $file != ".." ) {
echo $file.'<br>';
};
};

closedir( $handle );

?>


What happens if you leave off the 0755? That may be restricted in your
location. Just try it with the default.

If it still doesn't work, looks like it's time to find another host. This one
has too many restrictions.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 15 '06 #32

Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:

I asked my webhost, but they told me uploading
a folder and having it running uploads etc. is not
possible on Linux by default. Folders should be
chmod 777 or chmod 755.

Frizzle.
Yes and no. It depends on how they have their folders configured.

However, obviously they have it configured so you can't do it. But you should
still be able to create the folder in PHP from a web page (so it's running as
the Apache user) and upload to it. The folder should then have the Apache user
as the owner.

--
============= =====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@att global.net
============= =====

AFAIK the script below should be able to create dirs then
but i get the following error:

Warning: mkdir(testdir): Permission denied in
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 5

Warning: Cannot modify header information - headers already sent by
(output started at
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php:5) in
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 6

Frizzle.

+++++++++++++++ +++++++++++++++ +++++++++++++++ ++++++

<?php

if(isset( $_POST['dir'] ))
{
mkdir( $_POST['dir'], 0755 );
header('Locatio n: '.$PHP_SELF);
};
?><form action="<?php echo $PHP_SELF; ?>" method="post"
name="mkdirtest " target="_top" id="mkdirtest" >
<label for="dir">dir</label>
<input type="text" name="dir" id="dir"<?php echo isset( $_POST['dir']
) ? ' value="'.$_POST['dir'].'"' : '' ?>>
<label for="Submit"></label>
<input type="submit" name="Submit" value="mkdir!" id="Submit">
</form><?php

$handle = opendir('.');

while (false !== ($file = readdir($handle ))) {
if ($file != "." && $file != ".." ) {
echo $file.'<br>';
};
};

closedir( $handle );

?>


What happens if you leave off the 0755? That may be restricted in your
location. Just try it with the default.

If it still doesn't work, looks like it's time to find another host. This one
has too many restrictions.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===


Hmm, that's really crap. 755 does nothing more, and changing hosts
isn't really an option. ... :(

Frizzle.

Apr 17 '06 #33
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
>I asked my webhost, but they told me uploading
>a folder and having it running uploads etc. is not
>possible on Linux by default. Folders should be
>chmod 777 or chmod 755.
>
>Frizzle.
>

Yes and no. It depends on how they have their folders configured.

However, obviously they have it configured so you can't do it. But you should
still be able to create the folder in PHP from a web page (so it's running as
the Apache user) and upload to it. The folder should then have the Apache user
as the owner.

--
=========== =======
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@a ttglobal.net
=========== =======
AFAIK the script below should be able to create dirs then
but i get the following error:

Warning: mkdir(testdir): Permission denied in
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 5

Warning: Cannot modify header information - headers already sent by
(output started at
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php:5) in
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 6

Frizzle.

++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++

<?php

if(isset( $_POST['dir'] ))
{
mkdir( $_POST['dir'], 0755 );
header('Locatio n: '.$PHP_SELF);
};
?><form action="<?php echo $PHP_SELF; ?>" method="post"
name="mkdirt est" target="_top" id="mkdirtest" >
<label for="dir">dir</label>
<input type="text" name="dir" id="dir"<?php echo isset( $_POST['dir']
) ? ' value="'.$_POST['dir'].'"' : '' ?>>
<label for="Submit"></label>
<input type="submit" name="Submit" value="mkdir!" id="Submit">
</form><?php

$handle = opendir('.');

while (false !== ($file = readdir($handle ))) {
if ($file != "." && $file != ".." ) {
echo $file.'<br>';
};
};

closedir( $handle );

?>

What happens if you leave off the 0755? That may be restricted in your
location. Just try it with the default.

If it still doesn't work, looks like it's time to find another host. This one
has too many restrictions.
--
============= =====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@att global.net
============= =====

Hmm, that's really crap. 755 does nothing more, and changing hosts
isn't really an option. ... :(

Frizzle.


But unfortunately, it looks like your host has too many things locked down for
you to be able to upload files through the website.

I can partially understand their reasoning in a shared environment. But at the
same time, other hosting companies can do it. So why can't they?
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 17 '06 #34
Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:

Jerry Stuckle wrote:
>frizzle wrote:
>
>
>>I asked my webhost, but they told me uploading
>>a folder and having it running uploads etc. is not
>>possible on Linux by default. Folders should be
>>chmod 777 or chmod 755.
>>
>>Frizzle.
>>
>
>Yes and no. It depends on how they have their folders configured.
>
>However, obviously they have it configured so you can't do it. But you should
>still be able to create the folder in PHP from a web page (so it's running as
>the Apache user) and upload to it. The folder should then have the Apache user
>as the owner.
>
>--
>=========== =======
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>js*******@a ttglobal.net
>=========== =======
AFAIK the script below should be able to create dirs then
but i get the following error:

Warning: mkdir(testdir): Permission denied in
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 5

Warning: Cannot modify header information - headers already sent by
(output started at
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php:5) in
/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 6

Frizzle.

++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++

<?php

if(isset( $_POST['dir'] ))
{
mkdir( $_POST['dir'], 0755 );
header('Locatio n: '.$PHP_SELF);
};
?><form action="<?php echo $PHP_SELF; ?>" method="post"
name="mkdirt est" target="_top" id="mkdirtest" >
<label for="dir">dir</label>
<input type="text" name="dir" id="dir"<?php echo isset( $_POST['dir']
) ? ' value="'.$_POST['dir'].'"' : '' ?>>
<label for="Submit"></label>
<input type="submit" name="Submit" value="mkdir!" id="Submit">
</form><?php

$handle = opendir('.');

while (false !== ($file = readdir($handle ))) {
if ($file != "." && $file != ".." ) {
echo $file.'<br>';
};
};

closedir( $handle );

?>

What happens if you leave off the 0755? That may be restricted in your
location. Just try it with the default.

If it still doesn't work, looks like it's time to find another host. This one
has too many restrictions.
--
============= =====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@att global.net
============= =====

Hmm, that's really crap. 755 does nothing more, and changing hosts
isn't really an option. ... :(

Frizzle.


But unfortunately, it looks like your host has too many things locked down for
you to be able to upload files through the website.

I can partially understand their reasoning in a shared environment. But at the
same time, other hosting companies can do it. So why can't they?
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===


I guess you're right, but i really really don't want to change hosts. I
have multiple
sites hosted there, knowing their service etc. is great. (And still is)
This is the
first kind of problem i've come across.

I mailed them with my problem, and saying i don't want to swich, and if
they can
come up with another solution. If not, then i'll see ...

I looked into another old site on one of their servers wich was meant
as an online
diary with a photo gallery. I created an upload-module for photos.
These were
automatically resized by PHP. Looking through Plesk's file manager, i
can see the
folder the pics end up in is chmodded rwx r-x r-x (755), pics are rw-
r-- r-- (644)

Pics and folder have the same owner, and belong to the same group. Pics
are as
i said PHP created, the folder was done in dreamweaver, but probably
chmodded
manually. I wonder if this is possible for other files then images,
because they
don't have to be resampled, so aren't actually created by PHP.

I hope you get what i'm saying.

Frizzle.

Apr 18 '06 #35
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
>Jerry Stuckle wrote:
>
>
>
>>frizzle wrote:
>>
>>
>>
>>>I asked my webhost, but they told me uploading
>>>a folder and having it running uploads etc. is not
>>>possib le on Linux by default. Folders should be
>>>chmod 777 or chmod 755.
>>>
>>>Frizzl e.
>>>
>>
>>Yes and no. It depends on how they have their folders configured.
>>
>>However , obviously they have it configured so you can't do it. But you should
>>still be able to create the folder in PHP from a web page (so it's running as
>>the Apache user) and upload to it. The folder should then have the Apache user
>>as the owner.
>>
>>--
>>========= =========
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>js******* @attglobal.net
>>========= =========
>
>
>AFAIK the script below should be able to create dirs then
>but i get the following error:
>
>Warning: mkdir(testdir): Permission denied in
>/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 5
>
>Warning: Cannot modify header information - headers already sent by
>(output started at
>/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php:5) in
>/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 6
>
>Frizzle.
>
>++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++
>
><?php
>
> if(isset( $_POST['dir'] ))
> {
> mkdir( $_POST['dir'], 0755 );
> header('Locatio n: '.$PHP_SELF);
> };
>
>
>?><form action="<?php echo $PHP_SELF; ?>" method="post"
>name="mkdi rtest" target="_top" id="mkdirtest" >
> <label for="dir">dir</label>
> <input type="text" name="dir" id="dir"<?php echo isset( $_POST['dir']
>) ? ' value="'.$_POST['dir'].'"' : '' ?>>
> <label for="Submit"></label>
> <input type="submit" name="Submit" value="mkdir!" id="Submit">
></form><?php
>
>$handle = opendir('.');
>
>while (false !== ($file = readdir($handle ))) {
> if ($file != "." && $file != ".." ) {
> echo $file.'<br>';
> };
>};
>
>closedir ( $handle );
>
>?>
>
What happens if you leave off the 0755? That may be restricted in your
location. Just try it with the default.

If it still doesn't work, looks like it's time to find another host. This one
has too many restrictions.
--
=========== =======
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@a ttglobal.net
=========== =======
Hmm, that's really crap. 755 does nothing more, and changing hosts
isn't really an option. ... :(

Frizzle.


But unfortunately, it looks like your host has too many things locked down for
you to be able to upload files through the website.

I can partially understand their reasoning in a shared environment. But at the
same time, other hosting companies can do it. So why can't they?
--
============= =====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@att global.net
============= =====

I guess you're right, but i really really don't want to change hosts. I
have multiple
sites hosted there, knowing their service etc. is great. (And still is)
This is the
first kind of problem i've come across.

I mailed them with my problem, and saying i don't want to swich, and if
they can
come up with another solution. If not, then i'll see ...

I looked into another old site on one of their servers wich was meant
as an online
diary with a photo gallery. I created an upload-module for photos.
These were
automatically resized by PHP. Looking through Plesk's file manager, i
can see the
folder the pics end up in is chmodded rwx r-x r-x (755), pics are rw-
r-- r-- (644)

Pics and folder have the same owner, and belong to the same group. Pics
are as
i said PHP created, the folder was done in dreamweaver, but probably
chmodded
manually. I wonder if this is possible for other files then images,
because they
don't have to be resampled, so aren't actually created by PHP.

I hope you get what i'm saying.

Frizzle.


Yes, I see what you're saying. However, I don't think it should make a
difference like you think. Whether it's an image that's been sampled or a file
that's been uploaded, the Apache userid is doing the work.

The difference I can see is that the move_uploaded_f iles probably calls a system
function to actually move the files (don't know - I haven't looked). Obviously
the pix site doesn't do this when it resizes the pix; don't know what it does
before that, though.

the other possibility is they have the other server configured differently -
either PHP or the OS (or both). phpinfo() could tell you if there are PHP
differences.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 18 '06 #36
Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:

Jerry Stuckle wrote:
>frizzle wrote:
>
>
>>Jerry Stuckle wrote:
>>
>>
>>
>>>frizzle wrote:
>>>
>>>
>>>
>>>>I asked my webhost, but they told me uploading
>>>>a folder and having it running uploads etc. is not
>>>>possib le on Linux by default. Folders should be
>>>>chmod 777 or chmod 755.
>>>>
>>>>Frizzl e.
>>>>
>>>
>>>Yes and no. It depends on how they have their folders configured.
>>>
>>>However , obviously they have it configured so you can't do it. But you should
>>>still be able to create the folder in PHP from a web page (so it's running as
>>>the Apache user) and upload to it. The folder should then have the Apache user
>>>as the owner.
>>>
>>>--
>>>========= =========
>>>Remove the "x" from my email address
>>>Jerry Stuckle
>>>JDS Computer Training Corp.
>>>js******* @attglobal.net
>>>========= =========
>>
>>
>>AFAIK the script below should be able to create dirs then
>>but i get the following error:
>>
>>Warning: mkdir(testdir): Permission denied in
>>/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 5
>>
>>Warning: Cannot modify header information - headers already sent by
>>(output started at
>>/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php:5) in
>>/usr/local/psa/home/vhosts/host.com/httpdocs/test/mkdir.php on line 6
>>
>>Frizzle.
>>
>>++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++
>>
>><?php
>>
>> if(isset( $_POST['dir'] ))
>> {
>> mkdir( $_POST['dir'], 0755 );
>> header('Locatio n: '.$PHP_SELF);
>> };
>>
>>
>>?><form action="<?php echo $PHP_SELF; ?>" method="post"
>>name="mkdi rtest" target="_top" id="mkdirtest" >
>> <label for="dir">dir</label>
>> <input type="text" name="dir" id="dir"<?php echo isset( $_POST['dir']
>>) ? ' value="'.$_POST['dir'].'"' : '' ?>>
>> <label for="Submit"></label>
>> <input type="submit" name="Submit" value="mkdir!" id="Submit">
>></form><?php
>>
>>$handle = opendir('.');
>>
>>while (false !== ($file = readdir($handle ))) {
>> if ($file != "." && $file != ".." ) {
>> echo $file.'<br>';
>> };
>>};
>>
>>closedir ( $handle );
>>
>>?>
>>
>What happens if you leave off the 0755? That may be restricted in your
>location. Just try it with the default.
>
>If it still doesn't work, looks like it's time to find another host. This one
>has too many restrictions.
>
>
>--
>=========== =======
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>js*******@a ttglobal.net
>=========== =======
Hmm, that's really crap. 755 does nothing more, and changing hosts
isn't really an option. ... :(

Frizzle.
But unfortunately, it looks like your host has too many things locked down for
you to be able to upload files through the website.

I can partially understand their reasoning in a shared environment. But at the
same time, other hosting companies can do it. So why can't they?
--
============= =====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@att global.net
============= =====

I guess you're right, but i really really don't want to change hosts. I
have multiple
sites hosted there, knowing their service etc. is great. (And still is)
This is the
first kind of problem i've come across.

I mailed them with my problem, and saying i don't want to swich, and if
they can
come up with another solution. If not, then i'll see ...

I looked into another old site on one of their servers wich was meant
as an online
diary with a photo gallery. I created an upload-module for photos.
These were
automatically resized by PHP. Looking through Plesk's file manager, i
can see the
folder the pics end up in is chmodded rwx r-x r-x (755), pics are rw-
r-- r-- (644)

Pics and folder have the same owner, and belong to the same group. Pics
are as
i said PHP created, the folder was done in dreamweaver, but probably
chmodded
manually. I wonder if this is possible for other files then images,
because they
don't have to be resampled, so aren't actually created by PHP.

I hope you get what i'm saying.

Frizzle.


Yes, I see what you're saying. However, I don't think it should make a
difference like you think. Whether it's an image that's been sampled or a file
that's been uploaded, the Apache userid is doing the work.

The difference I can see is that the move_uploaded_f iles probably calls a system
function to actually move the files (don't know - I haven't looked). Obviously
the pix site doesn't do this when it resizes the pix; don't know what it does
before that, though.

the other possibility is they have the other server configured differently -
either PHP or the OS (or both). phpinfo() could tell you if there are PHP
differences.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===


PHP & OS are similar.
My upload function is below.
Hope it can get me/you any further ...
(again, really thanks for all the help!!)

Frizzle.

******* C O D E - A L E R T ! ! ! *************** *********
<?php

function ResizeUpload( $this_uploaded_ image )
{

global $album_id; // id of album where pic should end up in
global $conn_id;

$maxSize = 500;

$tmp_image = imagecreatefrom jpeg($this_uplo aded_image);
$width = imagesx($tmp_im age);
$height = imagesy($tmp_im age);

$maxSide = ( $width > $height ) ? $width : $height;

if ($maxSide > $maxSize)
{
$ratio = $maxSize / $maxSide;
$new_width = round( $width * $ratio, 0 );
$new_height = round( $height * $ratio, 0 );
}
else
{
$new_width = $width;
$new_height = $height;
};

$new_image = imagecreatetrue color($new_widt h, $new_height);
imagecopyresize d($new_image, $tmp_image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);

//Grab new image
ob_start();
imagejpeg($new_ image, '', 90);
$image_buffer = ob_get_contents ();
ob_end_clean();
imagedestroy($n ew_image);

//Create temporary file and write to it
$fp = tmpfile();
fwrite($fp, $image_buffer);
rewind($fp);

$created = date("YmdHis");

$addpic = mysql_query("IN SERT INTO photos (album_id) VALUES
($album_id)") or die(mysql_error ());
$this_image_nam e= substr('0000000 000'.mysql_inse rt_id(), -10, 10);

//Upload new image
if(ftp_fput($co nn_id,'/httpdocs/img/photos/'.$this_image_n ame.'.jpg',
$fp, FTP_BINARY))
{

$_SESSION['UploadedPics'] += 1;

}
else
{

$error_reportin g += 1;

};

fclose($fp);
};
$conn_id = ftp_connect('ft p.host.com');
ftp_login( $conn_id, 'loginname', 'pass')or die('Error :( ');

ResizeUpload($_ FILES['image']['tmp_name'] );

ftp_close($conn _id);

?>

Apr 18 '06 #37
frizzle wrote:
<old posts snipped>


PHP & OS are similar.
My upload function is below.
Hope it can get me/you any further ...
(again, really thanks for all the help!!)

Frizzle.


<code snipped>

Sorry for the delay - I missed this one when you posted earlier in the week.

Well, it isn't how I would have done it, but it should work.

First thing I would have done was to move the uploaded file from the temp
directory a working directory (move_uploaded_ file() ). This gets it completely
out of the temporary director (which could be something like /tmp) where there
may be limitations on what you can do with it.

Then I'd do the resizing or whatever I need in my workarea.

I'm also not sure why you're ftping back to yourself (at least I assume it's
yourself). Why not just store the file where you want it?

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 23 '06 #38

Jerry Stuckle wrote:
frizzle wrote:
<old posts snipped>


PHP & OS are similar.
My upload function is below.
Hope it can get me/you any further ...
(again, really thanks for all the help!!)

Frizzle.


<code snipped>

Sorry for the delay - I missed this one when you posted earlier in the week.

Well, it isn't how I would have done it, but it should work.

First thing I would have done was to move the uploaded file from the temp
directory a working directory (move_uploaded_ file() ). This gets it completely
out of the temporary director (which could be something like /tmp) where there
may be limitations on what you can do with it.

Then I'd do the resizing or whatever I need in my workarea.

I'm also not sure why you're ftping back to yourself (at least I assume it's
yourself). Why not just store the file where you want it?

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===


No problem with the delay, i was only hoping your last message hadn't
been sent. And luckily it hasn't.

Erm, this is an adjusted script of something i found somewhere.
I wouldn't know how to store it where i want ... :$ Shame on me.
I only have relative little time during the weeks to dig into PHP :(
Is there something you could point to me ( a script, preferrably
w/o classes)?

Frizzle.

Apr 24 '06 #39
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
<old posts snipped>

PHP & OS are similar.
My upload function is below.
Hope it can get me/you any further ...
(again, really thanks for all the help!!)

Frizzle.


<code snipped>

Sorry for the delay - I missed this one when you posted earlier in the week.

Well, it isn't how I would have done it, but it should work.

First thing I would have done was to move the uploaded file from the temp
directory a working directory (move_uploaded_ file() ). This gets it completely
out of the temporary director (which could be something like /tmp) where there
may be limitations on what you can do with it.

Then I'd do the resizing or whatever I need in my workarea.

I'm also not sure why you're ftping back to yourself (at least I assume it's
yourself). Why not just store the file where you want it?

--
============= =====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@att global.net
============= =====

No problem with the delay, i was only hoping your last message hadn't
been sent. And luckily it hasn't.

Erm, this is an adjusted script of something i found somewhere.
I wouldn't know how to store it where i want ... :$ Shame on me.
I only have relative little time during the weeks to dig into PHP :(
Is there something you could point to me ( a script, preferrably
w/o classes)?

Frizzle.


Not really. When I need something like this I just code it up. But they're
typically special purpose and would need changing for your system.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 24 '06 #40

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

Similar topics

5
16818
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...
6
6704
by: Ask Josephsen | last post by:
Hi NG If I write the following: <?php $file="myfile.JPG"; if ( getmyuid()==fileowner ( $file ) ) { chgrp ( $file, getmygid() ); chown ( $file, getmyuid() );
1
4699
by: Xuan Yuan | last post by:
I'm using Windows XP Professional and have no FTP installed. Instead, I use Command Promt. I need to CHMOD a PHP file, so I type "CHMOD 775 file-path",but get "'CHMOD'is not recognized as an internal or external command,operable program or batch file"!Is this because I spelled it wrong?Or is it the computer's problem?
4
4838
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.
5
9555
by: Stewart | last post by:
Hi, I'm working on a program in VC++ right now that needs to set file permissions of a given file to 766 (read/write/execute). Now I've found the _chmod() function in the API help docs, but that only caters for read/write. Is there ANY way of setting 766 to a file through C++ at all? Many thanks. Mike
2
2921
by: Freebird | last post by:
Hello everyone, =] I need your help, I'm creating a script that will work in many servers, and there's this part, where you can update a list, so the script goes from the client's machine to the central server, opens the file, and in adda line by line in the client server, it's all working fine, but there's a problem, this list, can't be available to others, because if I do this:
1
2991
by: James Colannino | last post by:
Ok, so now I have a very interesting problem, this time related to os.chmod. I have the following in a text file: 0600. My script reads that number as a string and converts it to an integer for use with chmod. However, when I do this, instead of the rw------ permissions that I expect, I get ---x-wx--T. I tried placing 0600 directly in the command (chmod(filename, 0600)), and that worked as expected (I got rw------). So then I entered...
3
3770
by: webhead | last post by:
I have a web where users can upload photos, but they want to also be able to delete them. The directory can have chmod changes but it won't let me chmod the files and unlink them. I'm assuming it really is a chmod problem even though the error message is "no such file or directory", as I'm sure the name and path are right. Even my ftp program won't let me chmod the files, is this a safemode problem?
3
4768
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')
1
3216
by: lawrence k | last post by:
I've a simple script to transfer some files from one domain to another, with both domains living on the same server. The files in both directories are already chmod 777. Yet after transfer, I try to ensure that the file is 777, and I get an error. Why? for ($i=0; $i < count($transferArray); $i++) { $fileName = $transferArray; $commandAsString = "\cp -f /var/www/vhosts/mydomain.com/httpdocs/ site_specific_files/$fileName...
0
9657
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10822
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...
1
10577
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10241
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...
0
9359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7774
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
5642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3103
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.