I'm new in DirectAdmin. I'm facing a problem that when user try to create a folder, they will get error, "Unable to upload data." (refer to my code).
I think my code should be no problem as it can run smoothly in Localhost. The problem rise when I run on live server (DirectAdmin).
$id = $this->session->userdata('id');
$directory = "./image/userFolder/" . $id;
if(!is_dir($directory)) {
mkdir($directory, 0777, true);
}
$directory = $directory . "/" . $nameImage;
if(!imagejpeg($big_image, $directory)) {
$data['error'] = "Unable to upload data.";
return $data;
}
Hope to get answer or maybe something that I can look after. Thank you.
I managed to solve the problem. Basically my folder's permission is 0755. Then I change to 0777 that enable user to make folder (mkdir) in the server. You can learn more about permission here.
Related
My aim is to download multiple files into the folder on my localhost. I am uploading them using the HTML form.
Here is the code (really sorry that I can't give a link to the executable version of the code because it relies on too many other files and database if anyone knows the way then please let me know)
foreach ($_FILES as $value) {
$dir = '/';
$filename = $dir.basename($value['name']);
if (move_uploaded_file($value['tmp_name'],$filename)) {
echo "File was uploaded";
echo '<br>';
}
else {
echo "Upload failed";
echo '<br>';
}
}
So this little piece of code give me an error:
And here are the lines of code:
The problem is that the adress is correct, I tried enterring it into my file directory and it worked fine, I have seen some adviced on other people's related questions that // or \ should be used instead, but my version works just fine! Also I have checked what's inside the $_FILES and here it is if that's required for someone trying to help:
Thank you very much if anyone could help!!
You are trying to move the file to an invalid (or non-existent) path.
For the test you will write
$dir = 'c:/existing_dir/';
$filename = $dir.basename($value['name']);
If you want to move the file to a folder that is relative to the running file try
$dir = '../../directory/';// '../' -> one directory back
$filename = $dir.basename($value['name']);
By starting your file path with $dir = '/'; you are saying store the file on the root folder, I assume of C:
Apache if correctly configures should not allow you access to C:\
So either do
$dir = '../';
$filename = $dir.basename($value['name']);
to make it a relative path or leave the $dir = '/'; out completely
iam doing my project in codeigniter in that i used to create new directory to upload my images.now i need to delete my new directory for that i have tired this coding,
$dir = '/var/www/uploads/chat/'.$input['chat_id'];
system('/bin/rm -rf ' . escapeshellarg($dir));
but its not working for me.i have got this coding from this link http://stackoverflow.com/questions/1296681/php-simplest-way-to-delete-a-folder-including-its-contents what i need to do?
when you are creating the directory use 777 as permission like
mkdir('new_dir', 0777, true);
and then try the below code
if(rmdir('new_dir'))
{
echo "deleted";die;
}
else
{
echo "not deleted";die;
}
i checked it and found,if your folder has not right permission then it will not be deleted.
please try and let me know the status.
Here's my code; I've renamed the directories, obviously. ;)
$thepath = "/var/www/vhosts/sub.domain.co.uk/web/apps/storage/".$userclient."/evidence/".$scid."/".$doctype."/";
$testdir = is_dir($thepath);
if ($testdir == false) {
mkdir($thepath, 0777);
}
In this case, the following variables apply;
$userclient = '000';
$scid = '9263';
$doctype = 'Insurance Policy';
So, the path should be;
/var/www/vhosts/sub.domain.co.uk/web/apps/storage/000/evidence/9263/Insurance Policy/
I know this works, EVERYWHERE else in my code, I have other applications using an almost identical setup. But the one above, appears to be tripping up on /evidence/ - it sets the permissions to 755, but will then create the directories per time I run the code, if I set evidence to 777 (Octal).
I get the following error message using;
if (!#mkdir($thepath)) {
$error = error_get_last();
echo $error['message'];
}
mkdir(): No such file or directory
Any help would be greatly appreciated, I have to finish this application by Thursday - and this file upload part is the last bit!
Thank you!
PHP can't find directory in which you want to create other directory.
You need to set $recursive param as true:
mkdir($thepath, 0777, true);
Maybe you want to try mkdir($path,$mode,true) to create missing links as well?
I am trying to upload my php project into public server.
I made the image upload file when I create product or edit product.
It works in localhost, but when I move to public server, it is not working.
I think move_uploaded_file part does not working.
How can I change the link? or do I have to change anything?
When I see Filzilla, I can see remote site that it is '/www/eshopProject/inventory_images'.
And index file is '/www/eshopProject/storeAdmin'.
Do I have to change link like this?
I don't know how can I change the link.
Could you help me? uploading the image into public server is not working..
Is it any security issue? or something?
Please help me. Thanks.
--index.php--
$pid = mysql_insert_id();
//Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/product_$newname");
First of all check the permissions of the directory as mentioned in come of the comments.
If you have shell access "chmod 777 target_dir" or "chmod 707 target_dir" should be sufficient.
Second try to debug it using if's and the file_exists function(http://php.net/manual/en/function.file-exists.php).
Something like this.
$uploadedFile = $_FILES['fileField']['tmp_name'];
$destination = "../inventory_images/product_$newname";
if(file_exists($uploadedFile))
{
echo "file uploaded to temp dir";
}
else
{
echo "file upload failed";
exit();
}
if(move_uploaded_file($uploadedFile, $destination))
{
echo "upload complete";
}
else
{
echo "move_uploaded_file failed";
exit();
}
You can also check your current working directory by using the FILE or DIR constants(http://php.net/manual/en/language.constants.predefined.php).
Try this.
echo __FILE__;
echo dirname(__FILE__);
echo __DIR__;
Use the copy() method. For me it worked.
copy($tmp_file, Destination) or
copy($tmp_image, IMAGE_DIRECTORY . SAM . $product_image);
Make sure you have write file permissions set to the folder you are trying to upload too.
I recommend setting the folders to "755" permissions and retry. This would make the permissions a little tighter.
This question is a bit old but i recently faced a similar issue where even with permission 777 on the upload folder it wouldn't work.
The issue was that the SELinux (https://wiki.centos.org/HowTos/SELinux) was on enforcing mode so i had to change it to permissive mode and then the upload works perfectly.
I hope this can help someone facing this issue.
I am stuck on a simple script. I have tried Googling it and I have tried all of the stuff I found on Google but none of it has worked for me. I am trying to you the mkdir function but I keep getting an error that says: Warning: mkdir() [function.mkdir]: No such file or directory in /home/content/l/i/n/web/html/php/mkdir.php on line 6
Here is my code:
<?php
//Create the directory for the user
$directory = time() . rand(0, 49716) ;
if (mkdir("/users/$directory", 0777)) {
echo '<p>Directory was created successfully.</p>' ;
} else {
echo '<p>Directory was NOT created.</p>' ;
}
?>
I am placing the script called mkdir.php in the same folder as the users folder. The users folder has the permissions set to 0777. I am not sure why I keep getting this error because the users folder does exists. Any help is greatly appreciated.
if (mkdir("users/$directory", 0777)) {
:-)
Nevermind I figured it out. It was just that the first slash in "/users/$directory" should be "users/$directory".