Warning: file_put_contents(): failed to open stream:

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bradeigh9991
    New Member
    • Feb 2015
    • 1

    Warning: file_put_contents(): failed to open stream:

    I'm just started learning Programming and have tryed to create a Drag and Drop upload form. The problem that I am having is that when I drag and drop a file on to my drop area I receive a post code of 200 which show that its ok. After checking my upload directory the file was not uploaded and I have an error of:

    Warning: file_put_conten ts(../../../media/SeagateHDD/Uploads/): failed to open stream: Is a directory in /var/www/PHP/Drop_Upload.php on line 10. File Uploaded Successfully

    I belive that this means that my upload path is not correct
    but I have check four times and the path is correct. I then changed the permissions to 777 and still get the same 200 code with error. Can anyone help me?

    My Jquery is:
    Code:
    $(function(){
    
    	var obj = $('#Upload_form');
    
    	obj.on('dragover', function(e){
    		//prevent browser from open the file when drop off
    		e.stopPropagation();
    		e.preventDefault();
    		$(this).css('border',"3px solid #000000");
    	});
    
    	obj.on('dragleave', function(e){
    		//prevent browser from open the file when drop off
    		e.stopPropagation();
    		e.preventDefault();
    		$(this).css('border',"3px dashed #4a4a4a");
    	});
    
    	obj.on('drop',function(e){
    		//prevent browser from open the file when drop off
    		e.stopPropagation();
    		e.preventDefault();
    		$(this).css('border',"3px dashed #4a4a4a");
    
    		//retrieve uploaded files data
    		var files = e.originalEvent.dataTransfer.files;
    		var file = files[0];
    
    		upload(file);
    	});
    
    	function upload(file){
    		xhr = new XMLHttpRequest();
    
    		//initiate Request
    		xhr.open('post','../PHP/Drop_Upload.php');
    
    		//set headers
    		xhr.setRequestHeader('Content-Type', "multipart/form-data");
    		xhr.setRequestHeader('X-File-Name',file.fileName);
    		xhr.setRequestHeader('X-File-Size',file.fileSize);
    		xhr.setRequestHeader('X-File-Type',file.fileType);
    
    		//send the file
    		xhr.send(file);
    	}
    });
    
    And my PHP is:
    <?php
    
    $string =file_get_contents('php://input');
    $path = '../media/SeagateHDD/Uploads/';
    
    if ( !file_exists($path) ) {
      mkdir ($path, 0777);
     }
     
    file_put_contents($path,$string);
    
    echo 'File Uploaded Successfully';
    Last edited by Rabbit; Feb 18 '15, 08:13 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
Working...