I am using the flash uploader that comes with Quform for wordpress to allow up to 5 files. I am trying to retrieve the file names but i only ever get the first one. $filesA All the files upload without issue but I never get all the names.
Here is my code (php) I am using
$myfiles= $form->getValue('iphorm_x_x');
$filesA = $myfiles[0]['text'];
$filesB = $myfiles[1]['text'];
$filesC = $myfiles[2]['text'];
$filesD = $myfiles[3]['text'];
$filesE = $myfiles[4]['text'];
I only ever get the first file name. Not sure why or where it is going wrong
Many thanks
Patrick
Found the answer after using Marc B to get existing file names
$myfiles= $form->getValue('iphorm_x_x');
foreach ($myfiles as $file) {
echo File Name: ' . $file['text'];
}
:)
Related
In phalcon you can get uploaded file with this piece of code
//Check if the user has uploaded files
if ($this->request->hasFiles() == true) {
//Print the real file names and their sizes
foreach ($this->request->getUploadedFiles() as $file){
echo $file->getName(), " ", $file->getSize(), "\n";
}
}
each $file is an Phalcon\Http\Request\File instance.
But what if I want to create an file instance from an existing file on the server, how can I do that?
What I tried is this:
new Phalcon\Http\Request\File(array($fileDir));
But it returns an instance with empty properties.
any help would be appreciated :D
As per the documentation of that class I think the constructor does not expect an array. So just leave out the array( ) that you are passing to the constructor and you should be fine. Disclaimer: I did not check out the code and rely on the documentation being proper here.
Code example:
new Phalcon\Http\Request\File($fileDir);
But what if I want to create an file instance from an existing file on the server, how can I do that?
This class is designed to work with $_FILES superglobal, so as for me you are using wrong tool. I would create your own wrapper for using files that are already on server, or go for SplFileObject.
Anyway, how should parameter array look like you may be able to anderstand from here starting at line 74+ and it pretty reflects $_FILES structure.
I'm a newbie in SPL and recursiveIterator... So could you help me?
What I want to achieve :
I would like to find a file in a folders tree and i would like to obtain its path.
My folder tree could seems to be like this :
./ressources
./ressources/Images
./ressources/Images/Image01
./ressources/Images/Image02
./resources/Images/ImagesSub/Image03
./ressources/Docs
./ressources/Docs/Doc01
and so on...
I obtain the name of my File with sql query (warning : they never have an extension).
Now, i want to find the file's location by doing a recursive Iterator on './ressources' folder.
Then, when i've found the file, i would like to return the whole link './ressources/Folder/File'.
I've read Gordon's solution but it doesn't work, I tried only to echo something, but doesn't display anything.
Here is my code :
$doc_id = $bean->id;
$query = "SELECT a.document_revision_id FROM documents as a, document_revisions as b ";
$query .= "WHERE a.document_revision_id = b.id AND a.id = '" . $doc_id . "' LIMIT 1";
$results = $bean->db->query($query, true);
$row = $bean->db->fetchByAssoc($results);
$file_id = $row['document_revision_id'];
$ressources = './ressources/';
$iter = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($ressources, RecursiveDirectoryIterator::KEY_AS_FILENAME), RecursiveIteratorIterator::SELF_FIRST);
foreach ($iter as $entry) {
if ($entry->getFilename() === $file_id){
echo '<script> alert('.$entry->getFilepath().');</script>';
}
}
(i know doing an alert into a echo is bullsh*t, but whith sugar it is quite difficult to display something
Specifications
I'm trying to do this in a SugarCrm CE 6.5.2 logic_hook and it's running on archlinux. And my PHP version is 5.4.6
It is really urgent, so I would be reaaaally happy if you could help me!!
Thanks by advance!
EDIT FROM 12/10/09 2pm:
What is my sugar project and why i can't get the pathname from my database
I created a custom field in Documents module called folder_name_c. You fill it with the name of the folder (under ressources) where you want to upload your document.
I want to allow the user to move the file uploaded from its ancient folder to new one when i edit the document.
When editing a document, I did a after_retrieve hook to permit the logic_hook to work when editing (before, it was just done for edit view)
So, if i get the $bean->folder_name_c, it pick up the field's content. If i try sql, it will pick the folder_name_c only after i click "save".
So, i don't have any clue to get my old folder_name to create an
$old_link = '.ressources/'.$old_folder.'/'.$file_id;
I can only create the
$new_link = '.ressources/'.$bean->folder_name_c.'/'.$file_id;
So, after a long time, i figured out that i could browse my ressources folder and my sub folders to find my file named $file_id and then create the $old_link
FYI, by creating a new custom field under studio in sugar, i gained a lot of time.
I don't want to pass my life on adding a custom_code calling database or else. this is URGENT and recursive iterator seems to be simple and quick.
There is no method such as getFilepath for the (Recursive)DirectoryIterator, just use $entry itself, when used in a string context it's casted to such one (à la __toString):
$file_id = 'test';
$ressources = './ressources/';
// [...]
echo '<script>alert('.$entry.');</script>'; // is casted to a string which contains the full path
// results in alerting ./resources/SubFolder/test
I tested it with the same structure and without extension.
So, I've found out how to use recursive iterators for my problem!
Here is my code :
$ressources = './ressources/';
$directoryIter = new RecursiveDirectoryIterator($ressources);
$iter = new RecursiveIteratorIterator($directoryIter, RecursiveIteratorIterator::SELF_FIRST);
$old_path = '';
$new_path = $ressources.$bean->folder_name_c.'/'.$file_id;
chmod($new_path,0777);
foreach ($iter as $entry) {
if (!$directoryIter->isDot()) {
if ($entry->getFileName() == $file_id) {
$old_path = $entry->getPathName();
chmod($old_path, 0777);
copy($old_path,$new_path);
}
}
}
So i succeed to get my file's origin path! :)
But as always, there is a problem:
I want to cut and paste my file from $old_path to $new_path (as you can see in my code). The copy here works well, but i don't know where i have to unlink() the old_path.. if anyone knows ...
(and if i wrote the copy in the wrong line, just tell me please! :D )
How do I find the filename of an image on a MediaWiki site?
I don't want to put the filename in manually. I need PHP code which will fetch me the filename.
I can use $f = wfFindFile( '$filename' ); but HOW DO I GET $filename?
I've been looking at the FILE class but I can't figure out how to use File::getFilename(); I keep getting an error call to undefined method.
What am I doing wrong?
Explaining in more detail:
I would like to add the pin it button to my site so when you click on the button it post it on the pin it board with the image and description of the image. I need to use php to send the image information so it works on every page on my site. I can't code the image name manually each time.
So far I have the code:
<img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" />
Which works great except I need to put in a value for $f (image name). My question is how do I get the value of $f without having to put in in eg $f = wfFindFile( 'Sunset.jpg' );
I would have thought this would be a really common request for anyone trying to add pinterest to their site.
Thanks
The $filename you are looking for is basically how it is named in MediaWiki when it got uploaded, for example Landscape-plain.jpg. You will just use the wfFindFile() helper function to get a File object. Then call the methods:
$ php maintenance/eval.php
> $file = wfFindFile( 'Landscape-plain.jpg' );
> print $file->getName();
Landscape-plain.jpg
> print $file->getPath();
mwstore://local-backend/local-public/b/b0/Landscape-plain.jpg
> print $file->getFullPath();
/path/to/images/b/b0/Landscape-plain.jpg
> print $file->getTitle();
File:Landscape-plain.jpg
> exit
API documentation:
http://svn.wikimedia.org/doc/classFile.html
http://svn.wikimedia.org/doc/classLocalFile.html
EDIT BELOW
The file informations are available through a File object, so you definitely need to use wfFindFile() to get such an object.
To actually find the filename for the page the user is browsing on, you want to use the query context and get its title:
$context = RequestContext::getMain();
$t = $context->getTitle();
if( $title->getNamespace == 'NS_FILE' ) {
$filename = $title->getPrefixedText;
// do your stuff.
}
I have searched far and wide on this one, but haven't really found a solution.
Got a client that wants music on their site (yea yea, I know..). The flash player grabs the single file called song.mp3 and plays it.
Well, I am trying to get functionality as to be able to have the client upload their own new song if they ever want to change it.
So basically, the script needs to allow them to upload the file, THEN overwrite the old file with the new one. Basically, making sure the filename of song.mp3 stays intact.
I am thinking I will need to use PHP to
1) upload the file
2) delete the original song.mp3
3) rename the new file upload to song.mp3
Does that seem right? Or is there a simpler way of doing this? Thanks in advance!
EDIT: I impimented UPLOADIFY and am able to use
'onAllComplete' : function(event,data) {
alert(data.filesUploaded + ' files uploaded successfully!');
}
I am just not sure how to point THAT to a PHP file....
'onAllComplete' : function() {
'aphpfile.php'
}
???? lol
a standard form will suffice for the upload just remember to include the mime in the form. then you can use $_FILES[''] to reference the file.
then you can check for the filename provided and see if it exists in the file system using file_exists() check for the file name OR if you don't need to keep the old file, you can use perform the file move and overwrite the old one with the new from the temporary directory
<?PHP
// this assumes that the upload form calls the form file field "myupload"
$name = $_FILES['myupload']['name'];
$type = $_FILES['myupload']['type'];
$size = $_FILES['myupload']['size'];
$tmp = $_FILES['myupload']['tmp_name'];
$error = $_FILES['myupload']['error'];
$savepath = '/yourserverpath/';
$filelocation = $svaepath.$name.".".$type;
// This won't upload if there was an error or if the file exists, hence the check
if (!file_exists($filelocation) && $error == 0) {
// echo "The file $filename exists";
// This will overwrite even if the file exists
move_uploaded_file($tmp, $filelocation);
}
// OR just leave out the "file_exists()" and check for the error,
// an if statement either way
?>
try this piece of code for upload and replace file
if(file_exists($newfilename)){
unlink($newfilename);
}
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $newfilename);
I want to be able to open the provided URL (which is done via a form) that is an URL that will allow the server to save the file into a directory, for example:
http://www.google.co.uk/intl/en_com/images/srpr/logo1w.png
I want to save that logo into this directory:
img/logos/
Then it will add it to the database by giving it a random file name before so, e.g.
827489734.png
It will now be inserted to the database with the following:
img/logos/827489734.png
I do not want to use cURL for this, I like to work with fopen, file_get_contents, etc...
Cheers.
EDIT
$logo = safeInput($_POST['logo']);
if(filter_var($avatar, FILTER_VALIDATE_URL))
{
$get_logo = file_get_contents($logo);
$logo_directory = 'img/logos/';
$save_logo = file_put_contents($logo_directory, $logo);
if($save_logo)
{
$logo_path = $logo_directory . $save_logo;
A part of this code I need helping...
You need to specify a full file name when doing a file_put_contents(). A pure directory name won't cut it.