path of the file which is uploaded through yii Cuploadedfile - yii

I am curious . Is there any way to get the path of the uploaded file in yii . I Am using Cuploadedfile.

according to the http://www.yiiframework.com/doc/api/1.1/CUploadedFile, you can't get the file uploaded loaded location. But you should define the uploaded location and save the file name into database table as
$uploadedFile=CUploadedFile::getInstance($model,'image');
$fileName = "{$rnd}-{$uploadedFile}"; // random number + file name
$model->image = $fileName;
if($model->save())
$uploadedFile->saveAs(dirname(Yii::app()->request->scriptFile).'/images/products/'.$fileName);

Related

How to access pdf file outside of public_html in joomla site?

Actually i want to edit a module to fetch PDF file outside from public_html.
I already tried to change permission of that file from which i want to fetch PDF to 777.
I am trying to fetch PDF by following codes
$baseurl = JURI::base();
$outside_baseurl = $baseurl.'../pdf/name.pdf';
Shows this error
Cannot access file!
https://mysitedomain.com/../pdf/name.pdf
It's really not safe to access a file outside the scope of your public folder in the open like that. It has the potential to open serious security holes. If you are trying to do this to modify or use the PDF file for something inside PHP, you should be able to. If you are trying to send it to a user for download or preview, you might wanna try fpassthru(). Something like the example below.
<?php
$path = 'path/to/file.pdf';
$public_name = basename($path);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $path);
header("Content-Disposition: attachment; filename=$public_name;");
header("Content-Type: $mime_type");
header('Content-Length: ' . filesize($path));
$fop = fopen($path, 'rb');
fpassthru($fop);
exit;
This should serve your purpose.

how to add the script type file to yii frame work?

how i add this js file to yii framework.
we can add simple js file like that
$scripts->registerScriptFile($baseUrl . 'dd.js?' . $this->version);
but now i want also to define my js file type such as type="text/babel"
< script type = "text/babel" src = "abc.js" >

How does one load some variables at runtime in Photoshop Script?

I have about 200 folders with X images in each of them.
I have a master script in the root folder that does some stuff to the images.
Each folder has some variables specific to it and its contents.
I want my master script, when it parses folder Y, load some sort of a config file from within folder Y to get those variables, then when folder Z is to be parsed, load the config file from that one.
I know of #include "config.jsx" that I use at the moment to load it but its at the beginning of the script, I need something dynamic and doesn't need to be a jsx at all.
I store all my parameters in xml format and read that in using the XML objects in extendscript. As long as your parameters file is always named something like 'config.xml' it is easily located.
var file = new File( /c/folder/file.xml );
file.open("r");
var str = file.read();
var xml = new XML(str);

PHPMailer giving rtf file .txt extension

First time using PHPMailer within Yii and i've got the files to attach fine in email form using .doc, .rtf and .txt. I then tried to add the optional name to the file rather than the uploaded name and my rtf file was sent as a .txt file. Not sure why? Wondered if anyone could point me int he right direction.
$mail = new YiiMailer();
//$mail->clearLayout();//if layout is already set in config
$mail->setFrom('email#example.com', 'Me!');
$mail->setTo(Yii::app()->params['adminEmail']);
$mail->setSubject('Mail subject');
$mail->setBody('Simple message');
$mail->AddAttachment($dest . '/' . $file->tmp_name . '.' .$file->extension, $file->name);
Thanks in advance
Jonnny
Seems that if I pass all the arguments to the AddAttachment() it sends the RTF as a .doc file.
$mail->AddAttachment($dest . '/' . $file->tmp_name . '.' .$file->extension, $file->name, 'base64', $file->mime_type);
Jonnny

Create dummy index.html inside a new MKDR directory

I know this may be a silly question but i cant seem to find just a simple answer.
I have a php script that makes a directory for me when the user starts a new entry.
That directory holds photos for their gallery.
What i would like to do is also create One index.html file inside that new directory with a few lines of html code in it.
How do i do this?
Im guessing that the file would be made like so:
mkdir('users/'.$id.'/index.html',0755);
But how do i add the html into that index.html file?
Or do i have one file on the server and copy it over into there during the MKDIR process?
Anyways a really simple answer would be best as i am very slow in this learning thing.
Thank you
John
New edits.....
<?php
$id = 812;
mkdir('users/'.$id,0755);
chmod('users/'.$id,0777);
$fh = fopen( "users/".$id, "w+" ) or die( "Couldn't open file" );
fwrite( $fh, "<html><head /><body><h1>It Works!</h1></html>" );
fclose( $fh );
?>
Its giving me this error?
Warning: fopen(users/812) [function.fopen]: failed to open stream: Permission denied in stackoverflowtest1.php on line 9
Couldn't open file
Any ideas? I am on a wamp windows 7 server and not using ftp to edit files but just the www wamp explorer foler.
I'm not sure which language you are using so you'll either need to update your question or forgive the lack of concrete code. mkdir is for generating directories and not flat files. To do that you'll need to open then the file handle then print the HTML lines to that handle and then close it.
A file handle is a pointer to a file. It allows you to manipulate the data in that file ( i.e. read or write it ).
example code:
$fh = fopen( "path/to/file/index.html", "w+" ) or die( "Couldn't open file" );
fwrite( $fh, "<html><head /><body><h1>It Works!</h1></html>" );
fclose( $fh );
The path to the file needs a file name as a target, sorry that wasn't clear.