File upload with jQuery file upload plugin - php

Hi I have the following problem. I use jQuery file upload plugin and want to implement file uploader in one of my website pages. I am using the UI version so the thing is working, the files are uploaded but when i try to delete them i have an 404 error on the request. I am using POST request. The problem is that I get 404 header error and that is screwing the code. My page is responding with the right JSON data but the header is 404 I searched the whole [uploader class][3], but i can't find where the header is set and even if I comment that 404 line
if (!$this->is_valid_file_object($file_name)) {
return $this->header('HTTP/1.1 404 Not Found');
}
Nothing happens so I cant understand where in which javascript file or in the upload handler class the headers go wrong and how to fix the problem.
So my ajax return is like follows:
_method:DELETE
/my_domaing/some_page/uploadAction/file:action_test_file_3%20%281%29.doc
POST 404 Not Found text/plain jquery.js:8706 Script 991 B 360 B 20 ms 20 ms
I think the problems comes from my framework cause in plain php I can upload and delete files. But when i open the page in my browser with that link I can see the JSON response which is:
{"file":{"name":"action_test_file_3.doc", "size":61440,
"url":"http:\/\/my_domain\/files\/action_test_file_3.doc",
"deleteUrl":"http:\/\/my_domain\/some_page\/uploadAction\/file:action_test_file_3.doc\/
_method:DELETE\/file:action_test_file_3.doc\/_method:DELETE","deleteType":"POST"}}
I don't know what I need to get so the file be deleted, but I know that the header information is gone wrong cause I can open it and see the information but the POST request sees the 404 error and just doesn't do nothing.
The framework I use have a .htaccess rewrite rule which is the following:
RewriteEngine On
RewriteRule !\.(js|ico|gif|jpg|png|css|swf|htc|txt|doc|docx|xls|xlsx|pdf|htm|html|
bmp|flv|xml|zip|plist|ipa|woff|ttf|svg|eot)|^design(.*)|^sks(.*)$ index.php
But I don't think the rule has anything to do with this upload. My framwork uses Smarty. I really can't find the way to solve the problem the uploading is working perfectly so why not the deleting. And I have write/delete permissions on the directory.
I don't get any javascript errors and in my php log there are not errors regarding this page.
So I think the problem is with the header information and if it returns 404 the file is just not deleted that is all. But I can't understand where and how this is happening.
So feel free to ask me anything but I can't send you a live demo cause it is a developer server, but I will do anything to try and resolve this problem cause I am struggling with it for almost 2 days. Any help is and will be appreciated!

Related

Weird entities in the URL breaks the link when using file_get_contents

I'm trying to save an image, with a link that includes: "r%c3%a9glisse"
When translated, it will be displayed: "réglisse".
The weird thing is, when I'm using the provided link with file_get_contents, it gets a HTTP 404 error, file not found.
I've tried several methods to encode/decode the link and so on, but without much luck.
So I'm wondering if anyone here knows how to solve this issue.
To check which is the file the is not found, check your web server access_log and error_log.
The problem may be that you are trying to file_get_contents() a "url encoded" uri. Try to open it "url decoded":
file_get_contents(urldecode("r%c3%a9glisse"));

PHP post.php mystery

I have a weird unexplainable phenomenon going on.
I downloaded some source code from a website, a basic PHP script. It came with an SQL to reference numbers as part of the script.
I uploaded the file called post.php and SQL file to my server and ran it - but - instead of executing the code in the PHP file, it loads the content of the webpage of the author of the source code. and stays on my server URL.
The code in the file has nothing to do with the author's site, or graphics or links or redirects or anything.
EVEN IF I delete the entire contents of the post.php file, run the empty file and it STILL LOADS CONTENT from the author's website, where I downloaded it from.
Refreshed browser, restarted, reloaded, you name it. How is this physically possible?
-----UPDATE
In addition when I try renaming PHP files on my server, they become permanently broken "oops broken link" error.
It would be very helpful if you could post some more specific details about what the script was, etc. But, here is my guess. Firstly, make sure that your web server is not doing any caching. If the problem persists, try getting rid of the post.php file itself. Then, I would check to see if the PHP script has created any HTML/PHP files on its own. If all else fails, try going into the code that you downloaded and see what its doing.

Debug php image generator script

I feel pretty stupid asking this... but I have a small php script that generates a image based on some GETs and output's it to the browser.
It works fine on my server, but I moved it over to the client's server and I get a 404 error instead of the image. Problem is I have no ideea how to see what is wrong.
Normaly I get an error in the browser so I know what is going on... but not beacase the output is an image I get nothing.
LE: I tried this, at the begining of the script:
error_reporting(E_ALL);
ini_set('display_errors', true);
but nothing.
If you get a 404, the PHP script is either not found or redirects to another resource (a generated and cached image file?) but the path to it is wrong (or the image file can't be generated because of right issues?).
As suggested, remove the header() if any (it's also probaly using a header if the script redirects to the real file after generation).
If the script is delivering the image directly without any redirect, then enabling errors won't help on a not found URL ;-)

Need help with my Wordpress Plugin

I need help in finishing a Wordpress plugin I'm developing. I'm almost finished, but I am experiencing some problems and I can't figure out why I get the errors. I am posting the link to the plugin so you may download and test. I think it's the best way to discover what is wrong
What does it do?
The plugin lets you select a image and stores the image URL in a custom property.
You can then retrieve this custom property in your template design.
When you install it, it will add two custom metaboxes to POST and PAGE edit screen in the backend. Each custom property has a button for selecting image. When you click this button, a UI Dialog box opens and displays files and folders.
Once you have selected an image and saved the POST / PAGE, you can retrieve the custom property and use the image url in your template design.
Installation
Just dowload the plugin from here: http://stiengenterprises.com/download/wp-filebrowser
Unzip and copy the folder to you/plugin dir, then activate the plugin.
Known issues
1) 404 Not found
When clicking the 'Get image url' button, jQuery triggers jQuery("#fileBrowser").dialog() which then loads 'fileBrowser.php'.
At line one, I have the following code:
require_once($_SERVER['DOCUMENT_ROOT'].'/wp-blog-header.php');
This is what is causing the 404 Not Found error. This line did not cause any troubles in WP v2.9.1.
2) File upload
I've not been able to use jQuery Form Plugin to uplaod files. I would really like to use this for file Upload. I do not want to use Flash.
I have had a go at it, but no luck :( You can see my Stackoverflow ticket here:
Does anyone have a good example / tutorial on how to use jQuery Form Upload?
I would really really appreciate any help you can give me :)
UPDATE
after testing Todd's suggestion, it works on my local installation of WPMU. But I still receive an error message on my web server:
Warning: require_once(WP_HOME/wp-blog-header.php) [function.require-once]:
failed to open stream: No such file or directory in
/home/mysite/wpmu/wp-content/plugins/wp-filebrowser/fileBrowser.php on line 4
Fatal error: require_once() [function.require]:
Failed opening required 'WP_HOME/wp-blog-header.php'
(include_path='.:/usr/local/php5/lib/php:/usr/local/lib/php') in
/home/mysite/wpmu/wp-content/plugins/wp-filebrowser/fileBrowser.php on line 4
Line 4 is require_once(WP_HOME.'/wp-blog-header.php');
404 Problem:
You do not have to use the
$_SERVER['DOCUMENT_ROOT']
In the WordPress wp-config.php there are the following constant:
define('WP_HOME','http://example.com');
Use these instead and that should fix your problem.
require_once(WP_HOME.'/wp-blog-header.php');
File Upload
This should get you pointed in the right direction:
http://ppshein.wordpress.com/2009/05/22/upload-files-with-jquery-ajax-and-php/
Thanks to Pavel Velikiy, I have fixed the 404 problem.
See separate thread here.
The solution was to add header('HTTP/1.1 200 OK') just after require_once.
As for upload part, I'll deal with that later :)
PS. I'm answering my own solution so I can mark it as solved.

Need help with uploading files using the Valums ajax upload script

No matter what I change in this script, when I go to upload the file, the page is looking for the action do-nothing.htm. This is what the ACTION of the plugin is set to in the downloaded example, but I have changed it.
I have also changed some lines in the Javascript to see if I could get something working, but nothing. In fact I can't seem to find any reference to do-nothing.htm yet the console still gives me a 404 error do-nothing.htm not found. Any ideas?
the example works.

Categories