Home › Forums › Plugin Support › Upload avatar/file failed
Tagged: unable to upload image
- This topic has 5 replies, 4 voices, and was last updated 12 years, 10 months ago by 
bluantinoo.
 
- 
		AuthorPosts
 - 
		
			
				
May 17, 2012 at 4:35 pm #1377May 17, 2012 at 9:25 pm #1379
Khaled
MemberHello,
We use tmpfile() function to creates a temporary file for file upload.
tmpfile() returns false if it is unable to create the temporary file. Make sure your tmp folder is writable and try and check what sys_get_temp_dir() function returns.
You can check if your temp directory is writable by following codes:
$tempDir = sys_get_temp_dir();
var_dump($tempDir);
var_dump(is_writable($tempDir ));If your temp directory is not writable by server, you need to chmod(775) your temp directory for proper permission.
Thanks
May 21, 2012 at 4:34 pm #1395giulioroggero
MemberThe problem of using tmpfile() is that, if you don’t have the possibility to change php.ini and you are on an hosted server, it’s not possible to use it. I’ve implemented a workaround using a php function found on stackoverflow.
[sourcecode]
// from http://stackoverflow.com/questions/8970913/create-a-temp-file-with-a-specific-extension-using-php
function mkstemp($template) {
$attempts = 238328;
// 62 x 62 x 62
$letters = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”;
$length = strlen($letters) – 1;if (strlen($template) < 6 || !strstr($template, 'XXXXXX'))
return FALSE;for ($count = 0; $count < $attempts; ++$count) {
$random = "";for ($p = 0; $p getSize()) {
return false;
}$target = fopen($path, “w”);
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);return true;
} else {
return false;
}
}function getName() {
return $_GET[‘qqfile’];
}function getSize() {
if (isset($_SERVER[“CONTENT_LENGTH”])) {
return (int)$_SERVER[“CONTENT_LENGTH”];
} else {
throw new Exception(‘Getting content length is not supported.’);
}
}}
[/sourcecode]- 
		This reply was modified 13 years, 5 months ago by 
giulioroggero. Reason: sourcecode formatting
 
January 3, 2013 at 11:26 am #2742teamdev
Memberi cant upload image in user meta can u help me
January 6, 2013 at 12:13 am #2747bluantinoo
MemberWhere is supposed to be the tmp folder?
I have the same problem and I cannot see any tmp directoryJanuary 6, 2013 at 1:32 am #2748bluantinoo
Membersorry: small update just to subscribe this post
 - 
		This reply was modified 13 years, 5 months ago by 
 - 
		AuthorPosts
 
- You must be logged in to reply to this topic.
 
