Jump to content

Search the Community

Showing results for tags 'file'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

  1. Hi, for a download page i need some links to files, which don't stay together in a "ul". They are distributed all over the page. I was wondering (and hoping) that there's a solution like the one for images: <?php $image = $page->images->eq(0); if($image) echo "<img src='$image->url'>"; ?> But i can't find something about it and a quick test didn't work. It worked for one single download: <?php $file = $page->download_files->eq(0); if($file) echo "<a href='$file->url'>$file->description</a>"; ?> When trying to address the 2nd file in the array with "eq(1)" nothing happens. What can i do to select the a specific file from the array? Mario
  2. Hi, I'm working on a script that allows users to add a new Page to my installation of ProcessWire. I will explain how this script works below. The user enters some information into a simple form ^ This can include an image The form is validated with jQuery When valid, the form triggers a function through a class that handles the process I will include some of the code below. Form: <form id="entry" class="entry" method="post" action="./" name="entry" enctype="multipart/form-data"> <div class="row"> <input type="text" name="fullName" id="fullName" placeholder="Naam initiatiefhouder *" data-validation="required" /> </div> <div class="row"> <input type="text" name="projectName" id="projectName" placeholder="Projectnaam *" data-validation="required" /> </div> <div class="row"> <input type="email" name="emailAddress" id="emailAddress" placeholder="E-mailadres *" data-validation="required" /> </div> <div class="row"> <textarea name="projectDescription" id="projectDescription" placeholder="Beschrijf uw initiatief *" data-validation="required"></textarea> </div> <div class="row"> <input type="file" id="image" name="image" data-validation="mime size" data-validation-allowing="jpg, jpeg, png, gif" data-validation-max-size="2M" /> </div> <div class="row"> <input type="submit" name="submitEntry" id="submitEntry" value="Insturen" /> </div> </form> So basically the "image" field is the field that allows the user to add a file (jpg, jpeg, png, gif - max 2mb). Now, when all the information is valid it will post this form through the following function. public function pushEntry ($input, $file) { // Unset the array $this->array = []; // If there is any data if ($input) { // Get some of the variables needed $this->name = $this->sanitizer->text($input->fullName); $this->email = $this->sanitizer->email($input->emailAddress); $this->project = $this->sanitizer->text($input->projectName); $this->description = $this->sanitizer->text($input->projectDescription); // Get the date $this->date = date("d-m-Y H:i:s"); // Generate the title $this->title = "$this->project - $this->name"; $this->duplicate = $this->pages->find("title=$this->title"); // Generate the array $this->array = [ "title" => $this->title, "fullName" => $this->name, "emailAddress" => $this->email, "projectName" => $this->project, "projectDescription" => $this->description, "date" => $this->date ]; // Create the page $new = new Page(); $new->template = $this->templates->get("entry"); $new->parent = $this->pages->get("/entries/"); foreach ($this->array as $key => $value) { // Foreach key and value, create a new page $new->$key = $value; } // Check if there is any duplicates if ($this->duplicate->count() == 0) { $new->save(); } else { echo "Dit initiatief bestaat al."; exit; } // If there is an image if (!empty($file["image"]["name"])) { // Some variables $this->path = $this->config->paths->assets . "files/$new->id"; // Set the extensions $this->extensions = [ "jpg", "jpeg", "png", "gif" ]; // Do the Wire $this->image = new WireUpload($file["image"]["name"]); $this->image->setMaxFiles(1); $this->image->setOverwrite(false); $this->image->setDestinationPath($this->path); $this->image->setValidExtensions($this->extensions); // Execute and check for errors $files = $this->image->execute(); // Add the image to the page $this->fileName = $file["image"]["name"]; $this->fullPath = $this->path ."/". $this->fileName; // Move the file $new->image->add($this->fullPath); // Unlink the file unlink($this->fullPath); // Save the page $new->save($new->id); } } // Return the array return $this->array; } The script adds a page to my installation of ProcessWire perfectly; except for the file upload. I encounter the following errors; Warning: unlink(C:/wamp/www/gezondsteregio/site/assets/files/1135/dekkleden_header.1919x301.jpg): No such file or directory in C:\wamp\www\gezondsteregio\site\templates\controllers\home.php on line 106 Warning: filemtime(): stat failed for C:/wamp/www/gezondsteregio/site/assets/files/1135/dekkleden_header.1919x301.jpg in C:\wamp\www\gezondsteregio\wire\core\Pagefile.php on line 324 Warning: filemtime(): stat failed for C:/wamp/www/gezondsteregio/site/assets/files/1135/dekkleden_header.1919x301.jpg in C:\wamp\www\gezondsteregio\wire\core\Pagefile.php on line 324 I am really curious if someone can help me with this problem. I have tried this script on both my localhost (regular Apache) and my webhost (Fast CGI). Regards, Jim Oh, and I use the following script to trigger the function. $entry = new Entry(); // If there is a post if ($input->post->submitEntry && !empty($input->post->fullName) && !empty($input->post->emailAddress) && !empty($input->post->projectName) && !empty($input->post->projectDescription)): // Push the entry to the controller $entry->pushEntry($input->post, $_FILES); endif;
  3. I wish to show various bits of information on a File repeater (extension, filesize etc). The filename shows correctly, but the links to the files open the admin area, the file extension is empty and the filesize too. function renderDocumentLibrary($page) { $out = ""; if ($page->document_download->count()) { print_R($page); $out .= "<div class='row downloads'>"; foreach($page->document_download as $download) { $out .= "<div class='col-xs-12 col-sm-6'>"; $out .= "<div class='download clearfix'>"; $out .= "<a href='{$download->url}'><img src='{$download->ext}' alt='Download {$download->document_name}' class='download-icon' /></a>"; $out .= "<div class='download-content'>"; $out .= "<span class='download-date'>" . date('d.m.y', $download->modified) . "</span><br />"; $out .= "<h2 class='h4'>{$download->document_name}</h2>"; $out .= "<a href='{$download->url}' class='download-link'>Download {$download->ext} ({$download->filesizeStr})</a></div>"; $out .= "</div></div>"; } $out .= "</div>"; } return $out; } Can I access those attributes in this way?
  4. Hello again. I have a silly problem. I feel a bit ashamed, really, but I have been searching for some time now, and I can't seem to find the issue. I have a simple site (first one I made with PW, actually), with a "file" field on a "news" template/page. So the webmaster can add a downloadable file to his news. It works fine, actually, but the field description, which should appear on the page, doesnt show up for guests. It does, as long as I am connected as an admin. But guest users (visitors) can't see it. No text is rendered. (the link itself is working.) I get the same result on local and distant site. I dont get it. Have I missed a permission setting or something ? The code for rendering the link is as follow : When connected as an admin, this outputs, for example, the following code : However, for a guest, the result is : Whatever I do. In the DB, the description is stored as : I have probably missed a simple setting somewhere about permissions. But I can't seem to find it. Maybe I'm just slow-brained today... Help ? Please ?
  5. Hi, I'm just trying to delete file field via API. I want to delete it completely without concerning which pages is using it. I found this code: $fields = wire('fields'); foreach ($fields->find('name=field_name') as $field) { foreach ($field->getFieldgroups() as $fieldgroup) { $fieldgroup->remove($field); $fieldgroup->save(); } $fields->delete($field); } This removes the field from database it is OK. But it doesn't remove the files (from filesystem) that ware added to pages. As I was going through PW source code I've found that I have to save the page also, but it really complicates the thing. The problem starts in FieldtypeFile::___deletePageField method where the $pagefile is handled differently according to field output formatting. If the $pagefile is PageFile, the unlink is called which also deletes the file from filesystem. If the $pagefile is PageFiles the deleteAll is called which only adds hooks on page save. Why is it done this way? This makes inconsistency when deleting the field. Is there some better way to delete the field without caring about pages?
  6. Hey guys, I'm creating a form via the API where a user can create a page and click to "create and duplicate". The idea is that this reloads the form with a GET variable to the page just created, takes the image from that page and also adds it to the new duplicate page. Essentially there may be 4 pages created but they should all share the same file. Would it be necessary to create a new WireUpload on every page creation or is there some way to do the following (or some variation): $duplicate_page->file->add($just_created_page->file); OR $duplicate_page->file->add($just_created_page->file->url); I don't seem to be able to pull this off but perhaps it's because the WireUpload needs to take place on every page creation.. Anyone had any experience with this? Thanks
  7. Hi there, I am kinda new to PW but I gave it a try for a current project and I am pretty amazed so far. It really works great and allthough I have pretty much no knowledge about PHP I can wrap my mind around these functions and also get lots of my queries working. My site is almost complete but I also struggeling with a problem which is the following. I am building a website for a music label. They want to provide a dedicated press and download area where press people can download latest press releases, music, artworks and stuff like this. The site structure should be like this: www.domain.com - Page 1 - Page 2 - and so on and the press area which should be www.domain.com/press The link to the press area is not visible on the main website. The page is hidden and should have a simple protection with htaccess. No user or login / member management required. Just a simple htaccess password protection. How can I do that? What I would normally do is just create a folder "press" on my FTP directory where I put the htaccess and thats it but how can I accomplish this in PW? I also provide downloads on that press page. These files for download have been uploaded via the backend and now sit in the assets/file folders. How can I protect them from being downloaded? I want to achieve that once people got access to www.domain.com/press that they are also able to download these files. Maybe its a simple task but I am not sure how to do this properly. Thanks for your help - I really appreciate all that kind support here in the forum! Cheers, Martin
  8. Hi, sorry, me again, I hope these nagging questions of mine may hopefully serve other people one day I have pages which contain files, which I can then link to students and I want to be able to flash up "New!" or some such like if the file has been added or updated within say 3 days. I've figured it out to check whether the page itself containing the file has been added or modified. $files = $file_page->files; foreach ($file_pages as $file_page) { $create_date = $file_page->created; $mod_date = $file_page->modified; $date_trigger = strtotime("-3days"); ?> <li><a href="<?php echo $file->url; ?>"><?php if ($file->description) {echo $file->description;} else { echo $file->name;} ?></a> <?php if ($mod_date>$date_trigger && $create_date<$date_trigger) {echo "Recently modified!";} ?> <?php if ($create_date>$date_trigger) {echo "New!";} ?> </li> Was wondering if it would be able to go one level deeper as I have some file pages with multiple files. If not, it's no big deal, but would be helpful. Thanks again.
  9. It will allow not to allow file load .psd with expansion on .jpg. Example: I have an external form. In type of a field it is specified (to allow.jpg.jpeg). But it is enough to rename only expansion as it will be possible to load and.psd and.png and.pdf and.php. Besides, everyone will be processed on a miscellaneous, instead of as jpg. For the sake of dough I suggest to load psd renamed into jpg
  10. Hi there, When I upload my files on the image field, it changes their name and uploads a file with a different name. In this case I am building a Retina ready site and I really need these files t be uploaded as they are. Their names end with '@2x', so 'file@2x.png' could be an example, but when I upload it, the file that appears on the assets/files/ folder is named 'file_2x.png'. How can I control this? Thanks
  11. Hi all, I have a situation in which a user can upload a file that's any one of a number of formats (pdf, mpg, jpg, etc.). If the file is an image, I want to do some resizing. However, when I call ->size(###,###) on the file field when an image is in it, I get an error. Makes sense. I'm hoping there's an easy way to solve this without needing to create a separate field for image uploads. I tried following @Soma's advice from this thread, but kept getting an error from ImageSizer saying I was passing in invalid format. I know the file in there is an image as it's getting displayed in the browser. So, is there a standard way to convert a File field to an Image field? Thanks.
  12. Hi y'all! Im am trying to force a file download after user submits a form. When user hits submit button POST data are send to a template (sort of "thank you for downloading" page). This template on successful submission redirects to another template through this code <?php $downloadurl = $pages->get('/download/')->url; header('refresh: 0; url='.$downloadurl); ?> Redirection then hits this template code (located in download template): <?php // filename & url of the pdf file $filename = $pages->get('/some-page/')->file->name; $fileurl = $pages->get('/some-page/')->file->url; $filesize = $pages->get('/some-page/')->file->filesize; // force download of the file header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename='.$filename); header("Content-Length: ".$filesize); readfile($fileurl); It downloads a file and then redirects back to thank you page. The only problem is that the downloaded file is empty (0KB). When i download a file "the standard way" clicking on a link that directs to $pages->get('/some-page/')->plik->url; everything is ok. Any ideas?
×
×
  • Create New...