File size problem

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-31-2005
Lee David
 
Posts: n/a
Default File size problem

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


Reply With Quote
  #2 (permalink)  
Old 03-31-2005
Kimmo Laine
 
Posts: n/a
Default Re: File size problem


"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!"
} ?>


Reply With Quote
  #3 (permalink)  
Old 03-31-2005
Lee David
 
Posts: n/a
Default Re: File size problem

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


Reply With Quote
  #4 (permalink)  
Old 03-31-2005
Kimmo Laine
 
Posts: n/a
Default Re: File size problem

"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.


Reply With Quote
  #5 (permalink)  
Old 03-31-2005
Lee David
 
Posts: n/a
Default Re: File size problem

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


Reply With Quote
  #6 (permalink)  
Old 03-31-2005
Lee David
 
Posts: n/a
Default Re: File size problem

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


Reply With Quote
  #7 (permalink)  
Old 04-01-2005
Kimmo Laine
 
Posts: n/a
Default Re: File size problem

"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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:19 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0