I am using Timthumb to reisze pictures in my wordpress blog.
It's woirking fine on my local machine but when upload it on remote server Timthumb return me the following error:
Could not find the internal image you specified.
And a 400 Bad request in browser console.
How to fix this? i've been told that it might depend from server path configuration.
Timthumb version i am using is: 2.8.10
I just had that error and it was because it was looking for the file in the wrong place in the filesystem. Enable debugging and set it to level 3. Open the page where it says this error. Download the error log (same directory as the script). You'll see all the paths it tries. Output dirname(__FILE__) from just about anywhere. You'll see the real path it needs. Add it to the timthumb-config.php as
$_SERVER['DOCUMENT_ROOT'] = '/home/username/public_html';
Just as an example I had to do this (wrap in php tag). Previously it was using something with /bin/usr/htdocs in it, and that's too much detail!
Around line 850 in the getLocalImagePath funcion, add this:
$src = str_replace ( "~username/" , "" , $src );
This is optional, replace username with something else.
Another case where you are using some htaccess magic so the images are accessed like /files/2012/02 rather than /wp-content/uploads/2012/02 TimThumb would work well if it'd treat this as an external URL... But it treats it as internal and it won't find the images so set a docroot accordingly and you might need to use the replace hack mentioned previously.
I have some tweaks on .htaccess to hide the fact that I'm using Wordpress.
On timthumb 2.8.11.
After
$this->localImage = $this->getLocalImagePath($this->src);
i'v hadded this line of code
$this->src = str_replace('/file/', '/wp-content/uploads/', $this->src);
The /file/ in the normal WPway should be /wp-content/uploads/.
Related
I am using Windows 10 and trying on my local. From backend, I am able to successfully upload image in backend/web/uploads folder and on frontend I tried to access via following code in gridview.
['attribute'=>'manufacturer_logo', 'label'=>'Logo', 'format' => 'html', 'value'=>function ($searchModel, $index, $widget) { return Html::img(Url::to('#web/uploads/' . $searchModel->manufacturer_logo),['width' => '50px']); }],
When I see image path from console then path looks like
/myprojectname/backend/web/uploads/home_page_default_image.png
I also tried path with http like
http://localhost/myprojectname/backend/web/uploads/home_page_default_image.png
but image is not showing, it is present in the folder, I am not able to find out what is the mistake?
Your code looks good. So, a short checklist:
Verify that the file exist
Try the URL to the file directly on browser, the image have to appear. If not check permissions but as you are on windows, I don't think this to be the issue.
You don't need to use Url::to inside Html::img. This one knows how to interpret #web alias
Remember, you save with path but to show you need to use url. So, you need to make sure you are pointing to the same location.
And this one here is the behavior we created to forget about upload issues. https://github.com/daxslab/yii2-uploader-behavior.
When you call #web in backend it loads domain/backend/web, but when you call it in frontend - it's domain/web or domain/frontend/web (I don't know if you have some htaccess rules) so here is your problem.
Image url is with backend.
You just set path like Url::to('/backend/web/uploads/' . $searchModel->manufacturer_logo)
or use another way to concatenate backend before all.
Also you can set new alias.
In common/config/bootstrap.php add this Yii::setAlias('#backendweb', '/backend');, so your image url will be:
Url::to('#backendweb/uploads/' . $searchModel->manufacturer_logo)
By default Yii2 generates file web/index.php with defined('YII_DEBUG') or define('YII_DEBUG', true); line. It's entry point of any page on site. And this the first line of a code. So checking for defined YII_DEBUG seems meaningless. I suppose this constant can be defined in something else place. But can't find where to do it.
In my personal case I have a local version of site and want to enable this constand for debugging purposes but don't want to change web/index.php. This file is under VCS (git) and I don't want to accidentally enabled debug in production.
StackOverflow has allready similar question. But it targeted on other sense and didn't give answer on my question. So I just created a new question.
Even if the index.php is default entry point for Yii app, you can still create your own entry point, include the index.php in it and set web server to use that file instead of index.php.
For example you can create custom-entry.php like this:
<?php
define('YII_DEBUG', false);
// do something ...
require index.php;
Or you can define YII_DEBUG in some script that is run at start of each request by auto_prepend_file directive.
But those are not exactly best options how to deal with your case.
In your case I would suggest to simply set your versioning system to ignore local changes of index.php file. For example if you are using GIT you can use skip-worktree flag to do that. I don't know CVS much so I'm not sure how exactly it is done with that.
Yii does it like that
defined('YII_DEBUG') or define('YII_DEBUG', true);
which means that if it's not defined already - define it.
This is a proper place to define it. The above statement is just in case somehow you got this already defined by any mean which Yii will honor.
I added this HTML to a page that I render via a REST call:
StringBuilder builder = new StringBuilder();
. . .
builder.Append("<p></p>");
builder.Append("<a href=\"/App_Data/MinimalSpreadsheetLight.xlsx\" download>");
builder.Append("<p></p>");
. . .
return builder.ToString();
My ASP.NET Web API project has a folder named "App_Data" which does contain a file named "MinimalSpreadsheetLight.xlsx"
The download link is indeed rendered on the page, and clicking it does appear, at first, to download the file (it has the Excel icon, and it bears the file name), but beneath that it says "Failed - No file":
Is the problem with my HTML, or the path I'm using, or file permissions, or what?
I've only tested this with Chrome, so far, BTW. IOW, it's not an IE issue.
UPDATE
I tried it with a leading squiggly, too:
builder.Append("<a href=\"~/App_Data/MinimalSpreadsheetLight.xlsx\" download=\"Spreadsheet file\">");
...yet, alas, to no avail.
UPDATE 2
I changed the pertinent line of HTML to this:
builder.Append("<a href=\"App_Data/MinimalSpreadsheetLight.xlsx\" download=\"Minimal Spreadsheet file\">");
...and it displays in the source like so (with some context):
<p>(Invoice Count excludes credits and re-delivery invoices)</p><p></p><p></p><a href="App_Data/MinimalSpreadsheetLight.xlsx" download="Minimal Spreadsheet file">
...but the link does not appear at all.
UPDATE 3
I was misled by this reference, which showed no text being added; I changed the code to this:
builder.Append("Spreadsheet file");
...(adding "Spreadsheet file" and closing out the anchor tag), and now the link appears; however, I still get the "Failed - No file" msg, and 2-clicking the "downloaded file" does nothing.
UPDATE 4
I tried two other permutations of what's seen in Update 3, namely with the forward whack reintroduced prior to "App_Data":
builder.Append("Spreadsheet file");
...and with both the squiggly prepended and the forward whack:
builder.Append("Spreadsheet file");
...but the results are the same in any of these permutations ("Failed - no file").
UPDATE 5
I also tried it without the "App_Data" at all, on the off change that is not needed:
builder.Append("Spreadsheet file");
...but the same "Failed - No file" is the result of that attempt, too.
UPDATE 6
Okay, so I tried this, too (single quotes):
builder.Append("<a href='/App_Data/MinimalSpreadsheetLight.xlsx' download='Minimal Spreadsheet file'>Spreadsheet file</a>");
...but no change. The file is there:
...so why is it not seen or accessible?
UPDATE 7
This:
string fullPath = HttpContext.Server.MapPath("~/App_Data/MinimalSpreadsheetLight.xlsx");
... (which I got from here) fails to compile with, "An object reference is required for the non-static field, method, or property 'System.Web.HttpContext.Server.get'
2-clicking the err msg highlights just "Server"
UPDATE 8
This (which I got from the same place as what I tried in Update 7):
string justDataDir = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();
string url2 = string.Format("Spreadsheet file</button>", justDataDir);
builder.Append(url2);
...does nothing; clicking the link doesn't even give me a fake/failed download now...
justDataDir is:
C:\Projects\ProActWebReports\ProActWebReports\App_Data
url2 is:
Spreadsheet file</button>
UPDATE 9
I noticed on further fine-tooth-combing that url2 had a forward whack in it; I changed it so that all the whacks were back, but it made no difference to Update 8's results: clicking the link does nothing whatsoever.
If somebody solves this, it will definitely get bountified after the fact.
UPDATE 10
Maybe what I really need to do is, instead of the simple html, add some jQuery that will download the file. But the question is, can jQuery access the App_Data folder any better than raw/simple html can?
The app_data folder is used by iis and asp.net as a private area in which to put database files which can only be accessed by code running on the server.
If you try to access the folder directly via your browser you will get a permissions error.
In order to make the files available for download, move them the a folder under 'Content' (if you have an mvc site) and ensure that your web.config allows the .xlsx exention to be downloaded.
It may depend on what version of iis you are using.
Downloading Docx from IE - Setting MIME Types in IIS
I have a simple question. When I create a CommaIO, it works but when I arrive to the 'if' statement, it doesn't go to inside the 'if'. The message 'blabla' is never printed. Nevertheless, the file name is correct and the path also. My csv files was saved in Excel with csv(comma delimited) extension. The file and directory are authorized in read mode
commaIO = new CommaIO(#"C:\\Users\\lbagno\\Documents\\SalesPrice.csv","r");
print "blabla";
pause;
print "fdf";
pause;
if(commaIO)
{
print "ici3";
pause;
}
Where is the problem ?
Thank you
When I first saw this I thought it was because you had \\ aswell as the # but seemingly in my code it works when I put it in a job.
Few questions.
try removing the \\ so it is just \ and see whether that fixes it (as I said it doesnt make a difference on mine)
Does the user running AX have access to that file path?
Does the file exist.
A few pointers for you, try using info("string") instead of print and pause, it's more standard and you dont have to pause every step.
Also commaIO has been superceeded by CommaTextIo. Looks like you can use the same code but I'm guessing it adds some functionality. http://msdn.microsoft.com/en-us/library/aa624902(v=ax.50).aspx
I can't comment on this post because of I don't have a high enough reputation so sorry if this isn't helpful as an answer.
Try moving the file to C:\Temp directory. It may be a permissions issue!!
The # makes it a string literal...so you're doing double \\ for no reason...but I think it still does work.
Use one of the two though:
CommaIo commaIO = new CommaIO(#"C:\Users\lbagno\Documents\SalesPrice.csv","r");
CommaIo commaIO = new CommaIO("C:\\Users\\lbagno\\Documents\\SalesPrice.csv","r");
Also, checking if (commaIo) will work if it finds a valid file, then you run while (commaIo.status() == IO_Status::Ok).
I'd say the issue is that either your file does not exist (as typed), it's a client/server issue, OR it's a permissions issue.
Start with a job and a local file.
I've been wondering this for a while now, but what is the best way to ensure that in a web app (RoR, Sinatra, PHP, anything) that when you are creating links (either generating with a method, or writing in by hand) that they go to the proper place whether you are on the root of a domain or not: http://www.example.com/ or http://www.example.com/this/is/where/the/app/is/
My thoughts are get the end-user to specify a document root somewhere in the config of your app, and use that, however I'm trying to think of a nice way to do it without the end-user having to configure anything.
Edit: By end-user, I mean the person setting up the application on a server.
Edit: I can use the beginning '/' to always get the link relative to the domain, but the problem is what if the app itself is not at the root, but some place like http://www.example.com/this/is/where/the/app/is/ so i want to say gen_link('/') and have it return /this/is/where/the/app/is/ or gen_link('/some/thing') and return /this/is/where/the/app/is/some/thing
How about trying to set the base element in the head of you html layout?
First, get the URL, eg. in a way Ilya suggests (if PHP is OK for you). After that you can use the base tag as follows:
<base href="<?= $full_site_url ?>" />
That will set the default URL for all the links and the browser will prepend it to every relative link on the page.
First of all you need to route all your urls through some kind of url re-writer function.
So you no longer do:
Foo
But instead something like:
Foo
All the web frameworks out there have a function like this. While they usually do all kinds of magic in there (to do with MVC controller paths and views and what not), at the end of the function (conceptually) they all prepend your url with a "root" (eg "/this/is/where/the/app/is/"), so as to allow you to create urls in your application that are independent of a hard-coded base path.
RoR uses a configuration directive called "relative_url_root".
Symfony (php) uses a configuration directive also called "relative_url_root".
CakePHP uses a configuration directive called "WEBROOT_DIR".
In cases where these frameworks are running on Apache, this value is often calculated dynamically (if you haven't set it explicitly). On other webservers the environment variables are often not available or are incorrect so this value cannot be determined consistently.
ilya's answer is a good one, but I think a simpler way to do this is just to precede all your links with a leading "/". This will ensure that they are always relative to the root of the domain:
Something <!-- Always links to www.domain.com/some/thing -->
Something <!-- Acutal destination depends current path -->
You can determine everything you need yourself, no need for configs.
Here’s a PHP example (let’s say index.php is your script name):
<?
$folder_on_server = substr ($_SERVER['PHP_SELF'], 0, strpos ($_SERVER['PHP_SELF'], '/index.php'));
$server_name = $_SERVER['SERVER_NAME'];
if (80 != $_SERVER['SERVER_PORT']) {
$server_name .= ':'. $_SERVER['SERVER_PORT'];
}
$full_site_url = 'http://'. $server_name . $folder_on_server;
?>
Now, you can always make a link like this:
Something
See also discussion in comments.