Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Relative path, getimagesize() and implode() 1

Status
Not open for further replies.

anulaibar

Programmer
Mar 1, 2003
17
0
0
SE
Hello!

I have a problem with my imageuploadingscript. I'm trying to pass a relative path as argument to the getimagesize()-function, but I'm doing something wrong. The code looks like this:

$uploaddir = "E:/$uploaddir_arr = explode("/",$uploaddir);

$id = time(); //give the image a unique name

$temp = array($my_url_arr[0],'//',$my_url_arr[2],'/', $uploaddir_arr[2], "/", $uploaddir_arr[3], "/", $id, $punkt, $filtyp['1']);
$ny_url = implode($temp);

$temp = array($uploaddir_arr[3], "/", $id, $punkt, $filtyp['1']);
$rel_url = implode($temp);
//$rel_url = "bilder/1069071787.jpg";
$bilddata = getimagesize($rel_url);

My problem is that the variable $rel_url does not work. As you can see I have tried the string 'bilder/1069071787.jpg'which works fine, but the variable doesn't.

You can see for yourself at
Any suggestions?

Olle
 
Impossible to say.

In this line:

$temp = array($my_url_arr[0],'//',$my_url_arr[2],'/', $uploaddir_arr[2], "/", $uploaddir_arr[3], "/", $id, $punkt, $filtyp['1']);

Your code makes reference to an array $my_url_arr that is not initialized in your posted code.

If immediately following the line I quoted above you add "print $temp;", what is output?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Sorry for not submiting all of my code, but here it is...

<?php

if (isset($_POST['submit'])) {

$my_url = &quot;['HTTP_HOST'].&quot;&quot;.$_SERVER['PHP_SELF'].&quot;&quot;;
$my_url_arr = explode(&quot;/&quot;,$my_url);

$uploaddir = &quot;E:/$uploaddir_arr = explode(&quot;/&quot;,$uploaddir);

$id = time();

$punkt = chr(46);
$filtyp = explode($punkt, $_FILES['bild']['name']);
$temp = array($uploaddir, $id, $bilddata['2'], $punkt, $filtyp['1']);
$gammal_url = implode($temp);

$temp = array($my_url_arr[0],'//',$my_url_arr[2],'/', $uploaddir_arr[2], &quot;/&quot;, $uploaddir_arr[3], &quot;/&quot;, $id, $punkt, $filtyp['1']);
$ny_url = implode($temp);
$temp = array($uploaddir_arr[3], &quot;/&quot;, $id, $punkt, $filtyp['1']);
$rel_url = implode($temp);
printf ('<br>%s<br>%s<br>%s<br>',$temp, $ny_url, $rel_url);
$bilddata = getimagesize($rel_url);

if (is_uploaded_file($_FILES[bild][tmp_name])){
copy($_FILES[bild][tmp_name],$gammal_url);
unlink($_FILES[bild][tmp_name]);
echo $rel_url;
echo &quot;<h2>Voilà!</h2>&quot;;
echo $_POST['bild'];
echo '<img src=&quot;'.$ny_url.'&quot;><br>';
echo &quot;&quot;.$_POST[bildtext].&quot;<br><br>\n&quot;;
echo &quot;<h5>Bildinformation:</h5>\n&quot;;
echo &quot;Namn: &quot;.$_FILES[bild][name].&quot;<br>\n&quot;; //The original name of the file on the client machine.
echo &quot;Mime-typ: &quot;.$_FILES[bild][type].&quot;<br>\n&quot;; //The mime type of the file, if the browser provided this information. An example would be &quot;image/gif&quot;.
echo &quot;Bredd: &quot;.$bilddata[0].&quot;<br>\n&quot;; //The widht of the uploaded file.
echo &quot;Höjd: &quot;.$bilddata[1].&quot;<br>\n&quot;; //The widht of the uploaded file.
echo &quot;Storlek: &quot;.$_FILES[bild][size].&quot; (&quot;.$bilddata[3].&quot;)<br>\n&quot;; //The size, in bytes, of the uploaded file.
echo &quot;Temporär lagring: &quot;.$_FILES[bild][tmp_name].&quot;<br>\n&quot;; //The temporary filename of the file in which the uploaded file was stored on the server.
echo &quot;Aktuell sökväg: &quot;.$ny_url.&quot;<br>\n&quot;; //The current url for the image
echo &quot;Felkod: &quot;.$_FILES[bild][error].&quot;<br><br>\n&quot;; //The error code associated with this file upload. ['error'] was added in PHP 4.2.0
echo '<a href=&quot;'.$my_url.'&quot;>Ladda upp en till bild</a>';
unset($_POST['submit']);
}
}
else{
?>
<h2>Ladda upp en bild</h2>
<form enctype=&quot;multipart/form-data&quot; method=&quot;post&quot; action=&quot;<?php echo $PHP_SELF ?>&quot;>
Bildtext<br>
<input type=&quot;Text&quot; name=&quot;bildtext&quot; size=&quot;25&quot;>
<br>
Bild<br>
<input type=&quot;File&quot; name=&quot;bild&quot; size=&quot;25&quot;>
<br><br>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Upload&quot;>
<input type=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;30000&quot;>

</form>
<?php
}
?>

Like you suggested I added print $temp; which returned 'array', the imploded variable $ny_url returns the full url of the image eg.
Olle
 
This line:

$my_url = &quot;['HTTP_HOST'].&quot;&quot;.$_SERVER['PHP_SELF'].&quot;&quot;;

Will generate a parse error just after the first semicolon.


Out of curiosity, why are you using implode to create your filenames? Why just just use the &quot;.&quot; concatenation operator?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I think that semicolon was added when I submitted my code, it's not in my file. I know the code is a bit messy, and I don't have any particular reason for using implode() :)

The errormessage I get when running my script is

Warning: getimagesize(bilder/1069090593.jpg): failed to open stream: No such file or directory in e:\ on line 23
bilder/1069090593.jpg


It's confusing because getimagesize() should be able to take 'bilder/1069090593.jpg' as an argument, shouldn't it?

Olle
 
What's funny is that if I do this

$rel_url = &quot;bilder/1069090593.jpg&quot;;
$bilddata = getimagesize($rel_url);

I get no error and the height and width of the image are available in the $bilddata-array....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top