Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a method that works</p> <p>PHP snippet </p> <pre><code>&lt;?php // initialize output; $output = true; // get the current user name to for dicroty placement $userName = $modx-&gt;user-&gt;get('username'); // valid extensions $ext_array = array('jpg', 'jpeg', 'gif', 'png'); // create unique path for this form submission $uploadpath = 'assets/userfiles/' . $userName .'/'; // get full path to unique folder $target_path = $modx-&gt;config['base_path'] . $uploadpath; // get uploaded file names: $submittedfiles = array_keys($_FILES); //get exsisting user profile data for Profile_Photos $fields = $modx-&gt;user-&gt;getOne('Profile')-&gt;get('extended'); $Photo_fields = $fields['Profile_Photos']; // loop through files foreach ($submittedfiles as $sf) { // Get Filename and make sure its good. $filename = basename( $_FILES[$sf]['name'] ); // Get file's extension $ext = pathinfo($filename, PATHINFO_EXTENSION); $ext = mb_strtolower($ext); // case insensitive if($filename != '') { $modx-&gt;log(modX::LOG_LEVEL_ERROR,'in file name loop'.$filename); // is this the right type of file? if(in_array($ext, $ext_array)) { //create file called the filename that has been sanitized $filename = strtolower(preg_replace("/[^A-Za-z0-9.]+/i", "-", $filename)); //$filename = $filename . '.'.$ext ; // full path to new file $myTarget = $target_path . $filename; // create directory to move file into if it doesn't exist mkdir($target_path, 0755, true); if(file_exists($myTarget)) { chmod($myTarget,0755); //Change the file permissions if allowed unlink($myTarget); //remove the file } // is the file moved to the proper folder successfully? if(move_uploaded_file($_FILES[$sf]['tmp_name'], $myTarget)) { // set a new placeholder with the new full path (if you need it in subsequent hooks) $hook-&gt;setValue($sf, $uploadpath . $filename); // set the permissions on the file if (!chmod($myTarget, 0644)) { /*some debug function*/ } } else { // File not uploaded $errorMsg = 'There was a problem uploading the file.'; $hook-&gt;addError($sf, $errorMsg); $output = false; // generate submission error } } else { // File type not allowed $errorMsg = 'Type of file not allowed.'; $hook-&gt;addError($sf, $errorMsg); $output = false; // generate submission error } } else { //check to see if there is exsisting photofields value and return value if so if ($Photo_fields != '') { $hook-&gt;setValue($sf, $Photo_fields); } else{ // if no file, don't error, but return blank // is the file name empty (no file uploaded) and exsiting photofields empty $hook-&gt;setValue($sf, ''); } } } return $output; </code></pre> <p><br> <br></p> <p>Change profile Form</p> <pre><code>[[!UpdateProfile? &amp;useExtended=`1` &amp;postHooks=`redirect_profile_update` &amp;preHooks=`user_profile_image`]] &lt;div class="update-profile"&gt; &lt;div class="updprof-error"&gt;[[+error.message]]&lt;/div&gt; [[+login.update_success:if=`[[+login.update_success]]`:is=`1`:then=`[[%login.profile_updated? &amp;namespace=`login` &amp;topic=`updateprofile`]]`]] &lt;form class="form" enctype="multipart/form-data" action="[[~[[*id]]]]" method="post"&gt; &lt;input type="hidden" name="nospam:blank" value="" /&gt; &lt;label for="fullname"&gt;&lt;i class="icon-user"&gt;&lt;/i&gt; &lt;strong&gt;[[!%login.fullname? &amp;namespace=`login` &amp;topic=`updateprofile`]]&lt;/strong&gt; &lt;span class="error"&gt;[[+error.fullname]]&lt;/span&gt; &lt;/label&gt; &lt;input type="text" name="fullname" id="fullname" value="[[+fullname]]" /&gt; &lt;label for="email"&gt;&lt;i class="icon-envelope"&gt;&lt;/i&gt; &lt;strong&gt;[[!%login.email]]&lt;/strong&gt; &lt;span class="error"&gt;[[+error.email]]&lt;/span&gt; &lt;/label&gt; &lt;input type="text" name="email" id="email" value="[[+email]]" /&gt; &lt;div class="row clearfix"&gt; &lt;div class="label"&gt;&lt;img src="[[+Profile_Photos:phpthumbof=`w=120&amp;h=120&amp;zc=1&amp;fltr[]=ric|20|20` ]]" /&gt;&lt;/div&gt; &lt;span class="error"&gt;[[+fi.error.Profile_Photos]]&lt;/span&gt; &lt;div class="input"&gt;&lt;input id="Profile_Photos" name="Profile_Photos" type="file" value="[[+fi.Profile_Photos]]" maxlength="100000" /&gt;&lt;/div&gt; &lt;/div&gt; &lt;br class="clear" /&gt; &lt;button class="btn-info btn btn-large" type="submit" name="login-updprof-btn"&gt;Update Profile&lt;/button&gt; &lt;/form&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload