not able to save file in files/myuploads folder in drupal 6 - file-upload

I want to upload a file inside the sites/default/files/myuploads folder. But I am not able to. Actually I am not able to upload the file to any of the folder inside sites/default/files/myuploads.
Here is my code:
$validators = array('file_validate_extensions' => array('se', 'SE'));
$file = file_save_upload('fname',$validators, 'public://myuploads', FILE_EXISTS_REPLACE);
if ($file) {
$fid = $file->fid;
$doc_url = file_create_url($file->uri);
//Set the status of the uploaded file.
$file->status = FILE_STATUS_PERMANENT;
//other code...
}
The upload will work fine if I just give public://. So it will be in the sites/default/files folder. And when I print the $file, in that the ["destination"] => "sites/default/files/./test.se"
How can I do this? Any idea how I can upload into the myuploads folder ?

Verify the write permission for "myuploads" folders.
Change the $validators variable like this:
$validators = array('file_validate_extensions' => array('se SE'));

Related

blueimp/jQuery-File-Upload - change upload path

I try to upload an image to my server by using blueimp/jQuery-File-Upload. The path is set to server/php by default in main.js and app.js and the files are saved to server/php/files/.
However, I need to save it to another location: fotos
I tried to change upload_dir and upload_url in server/php/UploadHandler.php to fotos/
public function __construct($options = null, $initialize = true, $error_messages = null) {
$this->response = array();
$this->options = array(
'script_url' => $this->get_full_url().'/'.$this->basename($this->get_server_var('SCRIPT_NAME')),
'upload_dir' => 'fotos/',
'upload_url' => 'fotos/',
But the images are not uploaded to the new path.
fotos/ must be /fotos/
Starts with a forward slash and ends with a forward slash.

file name automatically change when i upload the file

I'm new to CodeIgniter and having the following issue. When I upload a file, its successfully uploaded on my local folder and the file name saved to the db. The problem is, file name has been changed after uploading.
eg:
file name "screenshot image 123.png" -> "screenshot_image_123.png"
It just convert the space into underscore;this issue occurred only when the file name having space.Other than this issue all the other files uploading successfully. Given below is my code which I used on my controller page:
public function upload_pic()
{
$image_path = realpath(APPPATH . '../uploads');
$config['upload_path'] = $image_path;
$config['allowed_types'] = "gif|jpg|jpeg|png";
$config['file_name'] = $_FILES['file']['name'];
$config['encrypt_name'] = TRUE;
$config['overwrite'] = TRUE;
$this->load->library('upload',$config);
$this->upload->initialize($config);
if(!$this->upload->do_upload('file'))
{
echo $this->upload->display_errors();
}
else
{
$finfo=$this->upload->data();
$data['uploadInfo'] = $finfo;
}
}
Can anyone help me????
Try before saving file name generate some unique
$filename = $_FILES['file']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$filename = sha1_file($filename). md5(date('Y-m-d H:i:s:u')) . '.'. $ext; //not only this you can generate any format
$config['file_name'] = $filename; //Use this file name is db too

Max file uploadsize

I've the following code to upload a temp file within the server.
I would like to check the file size. If the file is larger than 25MB I would like to abort the proces. If the file size is less than 25MB I would like to proceed with the upload.
$tmp_name = $_FILES['filename']['tmp_name'];
$type = $_FILES['filename']['type'];
$file_name = $_FILES['filename']['name'];
$size = $_FILES['filename']['size'];
Anyone a suggestion?
Tnx for any reply.
You could use something such as:
if($_FILES['file']['size'] > 26214400) {
echo "File too large. Uploaded files can be no more than 25MB.";
} else {
... let them upload ...

Setting Sharepoint File Field Attributes

In out SP site, we have a library with files. These are files associated with a user. We now cstomized the user's profiles to accept a list of files. And now, to this list of files in the user's profile, we would like to add a reference to the file so that the user doesn't have to upload again.
Current Library:
/personal/my/User Files/[filename]
So, I was wondering how to do this? The data looks like this in the new User Files field (JSON):
{
[
{
"Id":"1",
"Title":"Test",
"Url":"\/personal\/my\/User+Files\/testfile.doc"
}
]
}
I have a csv file that I iterate over. The csv file contains the user name:filename pairs.
The Id value has to be gotten from the SP instance libarary at that location for that file.
Powershell code:
$upAttribute = "UserFiles"
$profile_info = Import-Csv profiles.csv
foreach ($row in $profile_info) {
$userId = $row.user # User ID
$fullAdAccount = $adAccount += $userId
#Check to see if user profile exists
if ($profileManager.UserExists($fullAdAccount))
{
$up = $profileManager.GetUserProfile($fullAdAccount)
$upAttributeValue += $row.filename # Filename
# CODE ??????
$up.Commit()
}
}
That is the all the data that I have.
Thanks for any and all help.
Eric
You will first need to add the custom property to the User Profile like so:
http://www.paulgrimley.com/2011/02/adding-custom-user-profile-property-to.html
Then this should help you out:
http://get-spscripts.com/2010/07/modify-single-value-user-profile.html
#Get user profile and change the value
$up = $profileManager.GetUserProfile($adAccount)
$up[$upAttribute].Value = $upAttributeValue
$up.Commit()

My file isn't being moved to the specified and newly created folder using mkdir

So I'm having an issue. When someone signs up for an account on the site I'm building, they go to a setup page where they can upload a profile picture. I'm using mkdir to auto create a sub-folder with their username which is working fine, and CHMOD is 777 on that sub folder. The problem I'm having is that image is not being moved to that specified sub-folder, but it's going into the "uploads" folder which is it's parent directory.
Hopefully I haven't confused anyone, but I'm really needing help.
Below is my script I wrote to do this.
===============================================================================
require_once('../admin/includes/config.php');
$uploaded_file = $_REQUEST['uploaded_file'];
$member_id = $_REQUEST['member_id'];
$name = $_REQUEST['name'];
$location = $_REQUEST['location'];
$hobbies = $_REQUEST['hobbies'];
$hobby = $_REQUEST['hobby'];
// using member_id, extract the username from the members table so we can auto create a sub-directory for the images
$result = mysql_query("SELECT username FROM members WHERE member_id = '$member_id'");
while($row = mysql_fetch_array($result))
{
$username = $row['username'];
}
// unmask to change CHMOD of newly created sub directory to 777
$old_mask = umask(0);
//Create directory with member's username
$madedir = mkdir('../admin/uploads/'.$username.'', 0777) /*== TRUE ? 1 : 0*/;
umask($old_mask);
// Assign the directory the file is going to be uploaded to
$uploaddir = '../admin/uploads/'.$username.'';
// Get the file name
$file_name = $_FILES['uploaded_file']['name'];
// Upload file to assigned directory with file name
$uploadfile = $uploaddir . basename($_FILES['uploaded_file']['name']);
// If the file has been uploaded, run this script
if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $uploadfile)) {
echo "Success";
} // end if
else {
echo "there was an error uploading your file";
}
You seem to be missing a / at the end of the upload directory. Change this:
$uploaddir = '../admin/uploads/'.$username.'';
to this:
$uploaddir = '../admin/uploads/'.$username.'/';