Download FOLDER

I use Uploadify to upload files and use the Codeigniter framework.

Here is my add code:

$("#change_profile_icon").uploadify({ 'uploader' : '/project/style/scripts/crop/uploadify/uploadify.swf', 'script' : 'http://localhost/project/pages/profile_icon', 'cancelImg' : '/project/style/scripts/crop/uploadify/cancel.png', 'buttonText' :'Upload image', 'width' : '110', 'height' : '30', 'queueID' : 'fileQueue', 'auto' : true, 'scriptData' :{username :"<?php echo $this->session->userdata('username');?>",folder:"honda"}, 'queueSizeLimit' : 1, 'multi' : false, 'fileDesc' : 'jpg', 'fileExt' : '*.jpg;*.png', 'sizeLimit' : '819200',//max size bytes - 800kb 'onComplete' : function(event,queueID,fileObj,response,data) { alert("Completed"); var dataresponse = eval('(' + response + ')'); //$('#uploadifyUploader').remove(); var filenametmp = "http://localhost"+(dataresponse.file).substring(0,(dataresponse.file).lastIndexOf("?")); var current_page = $('#page-list').val(); }, 'onSelect' : function (){ var folder = $('#page-list option:selected').text(); //returns HONDA which is correct $('#change_profile_icon').uploadifySettings('folder',folder); } , 'onError' : function(){ alert('error'); } }); 

Here is my part of PHP [uploadify script]

 function profile_icon() { if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_REQUEST['folder'] . '/'; $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']; // $fileTypes = str_replace('*.','',$_REQUEST['fileext']); // $fileTypes = str_replace(';','|',$fileTypes); // $typesArray = split('\|',$fileTypes); // $fileParts = pathinfo($_FILES['Filedata']['name']); // if (in_array($fileParts['extension'],$typesArray)) { // Uncomment the following line if you want to make the directory if it doesn't exist $targetPath = 'uploads/' .$_REQUEST['folder']. '/'; $targetFile = $targetPath.$_FILES['Filedata']['name']; if (!file_exists($targetPath)) { mkdir(str_replace('//','/',$targetPath), 0755, true); } move_uploaded_file($tempFile,$targetFile); echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile); // } else { // echo 'Invalid file type.'; // } } 

Problem:

 $targetPath = 'uploads/' .$_REQUEST['folder']. '/'; $targetFile = $targetPath.$_FILES['Filedata']['name']; if (!file_exists($targetPath)) { mkdir(str_replace('//','/',$targetPath), 0755, true); } 

Check out the above PHP codes. I think $_REQUEST['folder'] will indicate the folder name specified in the Uploadify script. The folder value is Honda But this gives something else.

I uploaded the file and this script uploaded it to

 C:\wamp\www\project\uploads\project\home\editpage\honda\honda 

On the wamp server [I am in Localhost]

But how is this obtained? it should be

  C:\wamp\www\project\uploads\honda 

Check below ...

  $targetPath = 'uploads/' .$_REQUEST['folder']. '/'; $targetFile = $targetPath.$_FILES['Filedata']['name']; 

targetPath should now be uploads/honda/ and targetFile should now be uploads/honda/fileName.ext

I do not know what I am doing wrong, and where is it ....

Please help me.

Thanks.

EDIT : STRUCTURE OF THE CURRENT PAGE URL: http://localhost/Project/home/editpage/honda/ Where home is the controller and editpage is the function and Honda is the argument. [Codeigniter framework]


 SOLVED 

I solved the problem, this is a mistake in uploadify: the uploadify folder variable is not direct, so we must add slash before this.

therefore it would be var folder = "/"+ "FolderName"; The problem is that you cannot return data to the server if you use only the folder name.

+4
source share
3 answers

I solved the problem, this is a mistake in uploadify: the uploadize folder variable is not straightforward, so before that you need to add a slash.

so it will be var folder = "/" + "FolderName"; The problem is that you cannot return data to the server if you use only the folder name.

+3
source

I will think that you will get a lot of help to put your output in a file:

 $myFile = "[full-folder-path]testFile.txt"; $fh = fopen($myFile, 'a') or die("can't open file"); $stringData = $_FILES['Filedata']['name'] ." | ". print_r( $_REQUEST, true ) ."\n"; fwrite($fh, $stringData); fclose($fh); 

But I think if you change your line of $ targetPath to this

 $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; 

Remember that your folder needs to read / wirte rulls, its only that I can see it worng from your main script to my script.

0
source

Just specify the folder where you want to load in the settings, as

 <script type="text/javascript"> $(document).ready(function() { $('#file_upload').uploadify({ 'uploader' : '/uploadify/uploadify.swf', 'script' : '/uploadify/uploadify.php', 'cancelImg' : '/uploadify/cancel.png', 'folder' : '/uploads', 'auto' : true }); }); </script> 

As in the above settings, you missed the folder option.

0
source

Source: https://habr.com/ru/post/1384898/


All Articles