php


PHP file_get_contents to get jquery min code


I am writing a script that will go through all my .js files and minify them into one .php file to be included on the site. I just run this script after I have edited some js and want to upload it to the live site.
The issue: I can not load the content of jquery-2.1.4.min.js using file_get_contents. I have tried changing the name of the file to jquery.js and that did not help. I do not have any complex javascript in the other files (just random strings) but they open fine.
With the code:
if (!file_get_contents($filename)) {
die ("dammit");
}
I get the response of "dammit". All other files are fine though, so I know the file name and path are correct. One of the weird things is that there are no errors coming up (I have used error_reporting (-1); to make sure they will).
Is anyone else able to get the file contents of jquery? Any ideas what would cause this and if it will be a problem with other javascript or css?
As requested, here is the full code:
$buffer = $jsStartBuffer;
//get a list of files in the folder (only .js files)
$fileArray = array();
if (is_dir($jsMakeFile["SourcePath"])){
if ($dh = opendir($jsMakeFile["SourcePath"])){
while (($file = readdir($dh)) !== false){
$file_parts = pathinfo($jsMakeFile["SourcePath"].$file);
if ($file_parts['extension'] == "js") {
$fileArray[] = $file;
}
}
}
}
print_r($fileArray);
foreach ($fileArray as $nextRawFile) {
$buffer .= file_get_contents($jsMakeFile["SourcePath"].$nextRawFile);
if (!file_get_contents($jsMakeFile["SourcePath"].$nextRawFile)) {
die ("dammit");
}
echo $jsMakeFile["SourcePath"].$nextRawFile;
}
$buffer .= $jsEndBuffer;
echo $buffer;
$buffer = \JShrink\Minifier::minify($buffer);
file_put_contents($jsMakeFile["finalFile"]["path"].$jsMakeFile["finalFile"]["name"], $buffer);
When I put other .js files in there it is fine (I even tried lightbox.min.js and it worked fine!) I have tried a few different versions of jquery.min and they all seem to fail.
OK, solution found. It is to do with the actual file created by jquery.
The way I solved it was:
- Go to the query site, and instead of downloading the required file, open it in a new tab/window
- Copy all the content in this window
- Create a new file where required and name as required
- Paste the content into this file and save it
This new file will now be able to be read by file_get_contents. I would imagine this solution would help if you are trying to work with jquery (and other) files in php in any way and having issues.

Related Links

PHP jQuery Ajax form submit using FormData
save current page url to node xml file
Twilio Gather - when a user hits pound without entering digits it does not proceed to next verb
SELECT DISTINCT rows
htaccess deny all allow remote access
Edit user info without change password if password field empty and edit it if we fill it with match confirm
preg match - on string vs on file_get_contents()
PHP refuses to echo strings shorter than 8 characters
How can I change mysql date format language [duplicate]
PHP setlocale/gettext and intl extension working together?
Lost connection to MySQL server at reading initial communication packet, system error: 111
How to using php count the word pair (string) array insert into MySQL
How to intercept a request, then load the content
Wordpress's WooCommerce Plugin compatibility with PHP 5.3
simple php: unable to execute C++ from php
Auto-logout of session after x seconds for a user type (Yii 1.x)

Categories

HOME
libgdx
svn
typelite
couchdb
swi-prolog
activemq
dry
ant
iverilog
jint
share
position
bellman-ford
chromecast
buffer
supervisord
office-ui-fabric
http-authentication
parceler
bluemix-mobile-services
dashdb
pymongo
pyopencl
managed-c++
plyr
high-availability
window-managers
echosign
python-imageio
math.js
docx4j
locks
matlab-app-designer
fotorama
char-pointer
dreamfactory
suds
contactless-smartcard
jshint
xcode8.2
uiautomatorviewer
password-hash
nusoap
asp.net-web-api-routing
stateless-session-bean
wildfly-9
gawk
ipywidgets
tablespace
livereload
data-management
groovyfx
meld
unsigned
uibinder
persistent-object-store
wepay
textpattern
stack-smash
opencyc
apache-commons-digester
fanotify
ambiguity
angular-amd
explain
directorysearcher
dos2unix
lifetime
datagridcomboboxcolumn
window-resize
visual-studio-6
storing-data
back
jquery-mobile-flipswitch
mfmessagecomposeview
zend-search-lucene
xulrunner
webaii
radius-protocol
django-sites
strdup
smips
visual-c++-2005
saga
illuminate-container
san
notifyjs
stty
tridion-2011
getopt-long
pageheap
fitch-proofs
kolite
motodev-studio
groovy-console
tablet-pc
3-tier
sscli
jquery-effects
prism-2

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile