blueimp/jQuery-File-Upload — Issue #1065: rename problem in IE all version
Author: bc080400222
Created: 2012-03-01 23:04:21+00:00
State: open

Hi everyone,
This is a great script i have implement this on my project. I have a small problem with rename files before uploading into folders. I have tried a lot to do so and now i am successful to achieve this but with little problem. This is working in chrome fine but except chrome it's giving me error something like this "SyntaxError: JSON.parse: unexpected character". Can anyone assist me how can i make it compatible with all browsers. I am sharing you my codes below. Please have a look at this code and let me know if you found some problem or suggest me better than it. Thanks

protected function handle_file_upload($uploaded_file, $name, $size, $type, $error) {
$file = new stdClass();

$project = $this->trim_file_name($name, $type);
$Ext = strrchr($project,".");
$project = md5(uniqid(rand()));
$project = substr($project,0,10);
$project = $project."$Ext";

$file->name = $project;
$file->size = intval($size);
$file->type = $type;
$error = $this->has_error($uploaded_file, $file, $error);
if (!$error && $file->name) {
$file_path = $this->options['upload_dir'].$file->name;
$append_file = !$this->options['discard_aborted_uploads'] &&
is_file($file_path) && $file->size > filesize($file_path);
clearstatcache();
if ($uploaded_file && is_uploaded_file($uploaded_file)) {
// multipart/formdata uploads (POST method uploads)
if ($append_file) {
file_put_contents(
$file_path,
fopen($uploaded_file, 'r'),
FILE_APPEND
);
} else {
move_uploaded_file($uploaded_file, $file_path);
}
} else {
// Non-multipart uploads (PUT method support)
file_put_contents(
$file_path,
fopen('php://input', 'r'),
$append_file ? FILE_APPEND : 0
);
}
$file_size = filesize($file_path);
if ($file_size === $file->size) {
if ($this->options['orient_image']) {
$this->orient_image($file_path);
}
$file->url = $this->options['upload_url'].rawurlencode($file->name);
foreach($this->options['image_versions'] as $version => $options) {
if ($this->create_scaled_image($file->name, $options)) {
$file->{$version.'_url'} = $options['upload_url']
.rawurlencode($file->name);
}
}
} else if ($this->options['discard_aborted_uploads']) {
unlink($file_path);
$file->error = 'abort';
}
$file->size = $file_size;
$this->set_file_delete_url($file);
} else {
$file->error = $error;
}
return $file;
}