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

upload script creating files with CHMOD 600

P: 5
Hi im trying to get images to upload into a directory on my server but i cannot get them to upload as chmod 755 so that they are viewable can anyone help?

[PHP]<?php include"connftp.php"; ?>

<? if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
&& ($_FILES["file"]["size"] < 100000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>[/PHP]
Feb 17 '07 #1
Share this Question
Share on Google+
7 Replies


P: 99
after you move the file you can use chmod.

[PHP]chmod('path/to/file/filename.ext',0755);[/PHP]
Feb 18 '07 #2

P: 99

[PHP]

<? if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
&& ($_FILES["file"]["size"] < 100000))

?>[/PHP]
if you only need to upload images it's best to check with getimagesize this gives you php fetched mime type instead of the browser fetched mime type which can not always be trusted. Contrary to it's name it doesn't get the file size.

[PHP]

<?
$imagesize = getimagesize($_FILES["file"]);
if (($imagesize['mime'] == "image/gif")
|| ($imagesize['mime'] == "image/jpeg")
|| ($imagesize['mime'] == "image/pjpeg") // don't forget the IE mime type
&& ($_FILES["file"]["size"] < 100000))

?>[/PHP]
Feb 18 '07 #3

P: 5
if you only need to upload images it's best to check with getimagesize this gives you php fetched mime type instead of the browser fetched mime type which can not always be trusted. Contrary to it's name it doesn't get the file size.

[PHP]

<?
$imagesize = getimagesize($_FILES["file"]);
if (($imagesize['mime'] == "image/gif")
|| ($imagesize['mime'] == "image/jpeg")
|| ($imagesize['mime'] == "image/pjpeg") // don't forget the IE mime type
&& ($_FILES["file"]["size"] < 100000))

?>[/PHP]
I can use the CHMOD script, but only to write individual file names, so if i use that i need to be able encompass the file name that is being uploaded into the script. ie
"/www/var/html/"$_files
But i havent been able to get it working :( with the embedded string
Feb 18 '07 #4

P: 99
Do you mean you want to upload multiple files?
Feb 18 '07 #5

P: 5
Do you mean you want to upload multiple files?

No i can specify the file (but i have to know what its called) meaning i will need to run CHMOD after the upload.

But what i want it to do is chmod it as its being uploaded (so using the string for the file name)
Feb 18 '07 #6

P: 99
It's not possible to set the chmod during the upload because php uploads the file to a temporary file.
Feb 18 '07 #7

P: 5
It's not possible to set the chmod during the upload because php uploads the file to a temporary file.
Thanks Xwero
Feb 18 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.