This is a discussion on File size problem within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I wasn't able to get an answer on this at alt.php so I thought I'd try it ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I wasn't able to get an answer on this at alt.php so I thought I'd try it
here. What I want to do is see the size of a photograph on the web site. I've tried using relative addressing (as when I display the photo) and absolute as well, but neither will return a non-zero value. I'm assuming I'm making a tyro mistake as I'm a neophyte. Here is the code I'm using on the unix server: <?php $my_source = $HTTP_SERVER_VARS["QUERY_STRING"]; $my_start = strpos($my_source,"=") + 1; $new_source = substr($my_source,$my_start); $my_source = "http://www.mokenamartialarts.com/" . substr($new_source,3); $my_size = filesize($my_source); $size = filesize($new_source) / 1024; $imgsize = round($size, 0); // echo "*testing* path is '" . $my_source . "'<br>\n"; // echo "*testing* imgsize is '". $imgsize . "' based on '" . $size . "' while my_size is '" . $my_size . "'<br>\n"; ?> Passed in the URL is code like this: http://www.mokenamartialarts.com/pho...mages/test.jpg Any pointers would be greatly appreciated! Lee |
|
|||
|
"Lee David" <affordable_turnkey_solutions@comcast.net> kirjoitti viestissä:qM-dnZ7Zf9YFxNHfRVn-1A@comcast.com... >I wasn't able to get an answer on this at alt.php so I thought I'd try it >here. > > What I want to do is see the size of a photograph on the web site. I've > tried using relative addressing (as when I display the photo) and absolute > as well, but neither will return a non-zero value. I'm assuming I'm > making a tyro mistake as I'm a neophyte. There are below some modification and three issues that may affect the result. My guess is that the file path is somehow incorrect, but that is just a hunch. > > Here is the code I'm using on the unix server: > > <?php > $my_source = $HTTP_SERVER_VARS["QUERY_STRING"]; > $my_start = strpos($my_source,"=") + 1; > $new_source = substr($my_source,$my_start); 1. Not the most conventional way of retrieving request variables. I'd just use plain old $new_source = $_GET['src']; // MOD a) it's faster and b) less confusing thus c) less likely the cause of troubles. Although it should work you've done it. But still there's no reason to do it like that... unless for some bizarre reason $_GET is not available. 2. But what's this? you're removing '../' ? Any particular reason? Also, is there a point in putting it there if you're gonna remove it anyway? I just don't get the general idea. > $my_source = "http://www.mokenamartialarts.com/" . substr($new_source,3); 3. Now is a good time to test if what we have here is indeed a file that exists. if(file_exist($my_source)) { // MOD echo "Yeah, the file exists!"; // MOD $my_size = filesize($my_source); $size = $my_size / 1024; // MOD echo "*testing* path is '$my_source'<br>\n"; // MOD echo "*testing* imgsize is '".((int)$size)."' based on '$size'"; // MOD echo "while my_size is '$my_size'<br>\n"; // MOD } else { // MOD echo "Where the heck is my file! I can't find it!" // MOD } // MOD ?> If you get the "Yeah, file exists" answer, we can start wondering why filesize cannot be read. Otherwise you should study really carefully where the files are and where you are pointing at. Can you give a direct link to test.jpg? The entire rewritten code without my comments: <?php $new_source = $_GET['src']; $my_source = "http://www.mokenamartialarts.com/" . substr($new_source,3); if(file_exist($my_source)) { echo "Yeah, the file exists!"; $my_size = filesize($my_source); $size = $my_size / 1024; echo "*testing* path is '$my_source'<br>\n"; echo "*testing* imgsize is '".((int)$size)."' based on '$size'"; echo "while my_size is '$my_size'<br>\n"; } else { echo "Where the heck is my file! I can't find it!" } ?> |
|
|||
|
Thank you for the reply.
I used the server variable because I didn't know of either "get" or "request" arrays. I admitted I'm a neophyte <g>. I'm assuming that I can include multiple entries in the URL and use "get" to isolate them. Sure would be easier than parsing the string as I was doing. I remove the "../" just to test trying it with a full URL rather than using relative addressing in http. Neither the full URL or the relative addressing worked. I'm going to assume I have to include a path (and find what the heck it is) rather than using URLs. BTW, I found the "request" variable by looking at each of the messages here. Is there a way to search for this stuff? "FIND" under OE doesn't do anything with text inside of a post. Lee |
|
|||
|
"Lee David" <affordable_turnkey_solutions@comcast.net> kirjoitti
viestissä:4fOdnaQOUKd-9dHfRVn-uQ@comcast.com... > Thank you for the reply. > > I used the server variable because I didn't know of either "get" or > "request" arrays. I admitted I'm a neophyte <g>. I'm assuming that I can > include multiple entries in the URL and use "get" to isolate them. Sure > would be easier than parsing the string as I was doing. Yes. separate entries with '&'. For example you call test.php?src0=pikachu.jpg&src1=charmander.jpg&src2 =bulbasaur.jpg And the variables can be all found as $_GET['src0'] (or in $_REQUEST) etc... > I remove the "../" just to test trying it with a full URL rather than > using relative addressing in http. Neither the full URL or the relative > addressing worked. I'm going to assume I have to include a path (and find > what the heck it is) rather than using URLs. Could you give a direct address to the image? Is it on the server? Where exactly? That way I might be able to tell you how you should give the path as parameter. I have no idea what you mean by including a path in this case... > BTW, I found the "request" variable by looking at each of the messages > here. Is there a way to search for this stuff? "FIND" under OE doesn't do > anything with text inside of a post. Oh, but it does. You just have to have all message bodies downloaded. It doesn't search from messages on the server. You can also use Google groups. Go to <URL:http://groups-beta.google.com/group/alt.comp.lang.php> and type in the "search this group" box what you're looking for. |
|
|||
|
I asked the host people, and they said the address on their server is
\home\net\aplus\web\user\html. This is on a unix server. I'm assuming "\" and not "/" and I'm assuming it is all in lower case. Under the html, I have added "dt" to have the demo team photos. There are four more directories that are sisters to "dt," but if I get it working for one I'm sure it will work for all of them. I'm not sure how to apply that to the filesize function, however. I'll be going to the google search function as soon as I post this. BTW, I appreciate the time you have given me on this. Lee |
|
|||
|
"Lee David" <affordable_turnkey_solutions@comcast.net> kirjoitti
viestissä:ddqdnbquTtSmGdHfRVn-rw@comcast.com... > Your point to the google search paid off. I found it was forward slashes > that I needed. Now I have that working and I have the google search in a > "favorite." > > Thanks again, > Lee No problemo |