I have a php site hosted in aws ec2 server.
While uploading files using php script it have only 0644(rw-r--r--) permissions in server. i need to change the file permissions to 0777(rwxrwxrwx).
What am doing is .. uploading a file and then read it and create a new encripted file using it and then delete the first file. its not happening because of file permission issue in aws uploading file through script.
uploaded files shows owner as 'apache' and transfer file using winSCP shows 'ec2-user'.
please help , am not much experinced in aws , so please please send your answers in detail.
Try This one.
Hope it will work
move_uploaded_file($temp_file, $UploadDirectory.$NewFileName );
chmod($UploadDirectory.$NewFileName, 0755);
$in_filename = $UploadDirectory.$NewFileName;
$aes_filename = //your path to new file with name;
$this->encryptFileCBC($in_filename, $aes_filename);
unlink($UploadDirectory.$NewFileName);
Related
I am using wamp server .
I wrote a code where user could upload file and the uploaded file will be stored in the server for further processing .
I wanted to restrict the executable file upload to this API
so that only .feature files can be uploaded.
is there any way in WAMP server that we could restrict such file uploads
You could restrict your file types with your script. Don't need to do things on WAMP.
Please see the below link for more info. It is explaining how to do it
This is what I have done so far.
Configured Filezilla FTP server on localhost.
And added user: Admin with shared folder C://ftp
there is a file inside that folder 123.jpg
So when I try to Download it using ftp class in Codeigniter;
Unable to download the specified file. Please check your path.
this is the code I'm using to download. FTP successfully connects but fails download due to incorrect file path.
$this->ftp->download('/123.jpg', 'D:/');
What should be changed in the above code?
Well, D:/ definitely dose not seems to be a path that is wrong. As for the doubt goes in the file you trying to download.
You can debug with the same - connect the ftp server using a ftp client, see the files / folders in list. There you can confirm as whether or not the file exists directly in path or not.
Solved it !
Seemed that local file path need to have the 'file name' at the end as well.
$this->ftp->download('/123.jpg', 'D:/blah.jpg');
And file would be downloaded to D: renamed as blah.jpg
I want user to upload an image via a form, then store it in a temporary folder to resize and convert it. After the image is converted, it can be uploaded to Amazon S3 server (I'm using tpyo S3).
The code works perfectly fine on local machine, but when it runs on my Ubuntu EC2 server, the image wont upload (even though it's converted). I tried different folder permission settings but nothing changed
This is my code:
$dir = "/var/www/html/inventorymanager/imageupload/";
//path to new file location
$moved_file = $dir.$uploadedFileName;
if(move_uploaded_file($tmpUploadedFile, $moved_file)) {
chmod($moved_file, 0775);
} else{
echo "There was an error uploading the file, please try again!";
}
//amazon file to upload name: create random name for the file to upload to S3 server
$amazonFileToUploadName = randomStringGen(30).".jpg";
//upload resized image to S3 server
S3::putObject(S3::inputFile($moved_file, false), "inventorymanager-huyvu", $amazonFileToUploadName, S3::ACL_PUBLIC_READ);
//delete processed file after it is uploaded
unlink($moved_file);
Hah. I just found the solution after spending 10 hours debugging the code and trying different methods to upload. I later found out that my server had not had CURL installed! This S3 tpyo class only works with CURL installed. Hope this would help someone's time
I'm trying to upload a file (msword/doc) to a Apache server folder via an HTML form. It works when I test it locally (I'm testing it via MAMP), but when I upload it to a remote server (such as GoDaddy), it doesn't work. It shows "There was a problem with the file upload".
Below is the snippet of code that processes the file upload. I can't figure out what is wrong with my conditional.
// Move the file to the target upload folder
$target = FILE_UPLOADPATH . basename($new_file);
if (move_uploaded_file($_FILES['new_file']['tmp_name'], $target))
{
// The new file move was successful, now make sure any old file is deleted
if (!empty($old_file) && ($old_file != $new_file))
{
#unlink(FILE_UPLOADPATH . $old_file);
}
}
else
{
// The new file move failed, so delete the temporary file and set the error flag
#unlink($_FILES['new_file']['tmp_name']);
echo 'There was a problem with the file upload.' . PHP_EOL;
}
Are you sure that the folder you are uploading to has permission for files to be written to it? If not, use chmod 0777 and test with that.
Does your destination folder have proper permissions? http://en.wikipedia.org/wiki/Chmod The directory write to typically needs 775: What are the proper permissions for an upload folder with PHP/Apache?
Also, do you want users to have direct access to the file? If not you should consider writing the file to a folder that is above your web root directory.
If $_FILES['new_file']['error'] == 0 then the upload isn't the problem, but the call to move_uploaded_file() is. You probably have incorrect permissions on the directory you're trying to move the file to.
For me, I happened to be testing locally with a file under php's upload_max_filesize while testing remotely with a file over upload_max_filesize. See https://stackoverflow.com/a/30359278/3325776 for more info.
i'm working on a website wherein the users can upload images (uses php 4.3.11). the files are uploaded with no problem as i can see them in the upload directory and i don't get any error message, but when i try to access the uploaded files via ftp, i get an error: no such file or directory. sometimes, i am able to access the file sometimes i get this error. what could be the problem here?
[update]
thanks for the help guys. i'm not familiar with the ftp daemon stuff. but i do access my files via ftp using FireFTP. the files are there but when try to download them or change the file properties, i get the said error. i also tried uploading a file in the folder through ftp and i was able to download it with no problem.
here is some of the code i'm working on, its kind of roundabout but i'll see on how to improve it.
my working directory is something like this www.domain.com/register/
and the upload directory is here www.domain.com/register/uploads/
users are required to register and upon sign-up, a folder is created for them in the uploads directory. i couldn't find a way to create a folder without having to be in the uploads folder itself so i redirect to a create-user-folder.php file in the uploads dir.
the file just contained this code:
$user_foldername = rawurldecode($_GET['name']);
mkdir($user_foldername);
header("Location: ../form.php"); // redirect back to the page
i checked and the created folder's permission is set to 775.
and here's part of the code i use in uploading ( /register/function/function.php ):
$path = "../uploads/$user_foldername/";
for($j = 0; $j < $num_of_uploads; $j++){
if(is_uploaded_file($_FILES[$file]['tmp_name'][$j])){
$filename = $_FILES[$file]['name'][$j];
copy($_FILES[$file]['tmp_name'][$j],$path.$filename);
}
}
i checked using FireFTP and the files are in the /uploads/user_foldername/ directory and its permission is set to 664. the strange thing is that when i try to download the files, at times there would be no problem at all but there are times when the error will appear.
[another update]
i added chmod() after the copy() function,
$filename = $_FILES[$file]['name'][$j];
copy($_FILES[$file]['tmp_name'][$j],$path.$filename);
chmod($path.$filename, 0755);
but i still get the error.
another thing is that when i access /register/uploads/user_foldername/ through the url, i can see all of the uploaded files and view them, but how is it that i can't access them via ftp?
thanks again!
This is either a permission issue, or a configuration error. Here are things you should try:
What are the permission of the uploaded files? Does the FTP user has access to these files? Have you tried logging in as the user the FTP daemon would use and see if you could read the file that way?
Do you really see the correct directory? Have you verified by putting a file in that directory yourself and downloading it? Have you used the ftp command ls to verify the presence of the folder/folders/files?
You might need to chmod the folder the files are in, or in some cases the files themselves.
try chmoding them to 775
You can chmod files and folders through PHP it's self, with the chmod function. Or, you could use a FTP program such as filezilla.
Also check to make sure the intermediate directories are also permissioned as 755, as all the directories in the path need to be executable to be traversed.
i just figured out the problem. it was all because of the file name having accented characters in it, which explains why i do not always get the error message :|
<sigh> i should have seen this earlier, but anyway i hope this helps in case someone ran into the same problem.
thanks again! i really appreciate it :)