Jump to content

image uploads but extension not showing


$php_mysql$

Recommended Posts

what am i doing wrong here friends?

 

$target = "images_thumbs/";
$randomnum=rand(0000,9999);
$target = $target.getnick_username($username).$randomnum;
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;

 

the image gets uploaded as username01234 the .jpg is not showing?

Link to comment
https://forums.phpfreaks.com/topic/240831-image-uploads-but-extension-not-showing/
Share on other sites

$target = "images_thumbs/";
$randomnum=rand(0000,9999);
$target = $target.getnick_username($username).$randomnum;

$aNew=pathinfo( $_FILES['uploaded']['name']);
$target = $target . "." . $aNew['extension'];

// $target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;

 

Maybe this helps ?

this is a bit of coding i got for resizing image but im not sure how i would go using it with my codes above

 

global $uploadPath;
$imagepath = uploadFile($_FILES['image'], $uploadPath);
// code to resize and save the original image
$image = new SimpleImage();
$image->load($imagepath);
$image->resize(204,250);
$thumb_path = 'image_thumbs/thumb_'.$_FILES['image']['name'];
$image->save($thumb_path);
//image resize end

unlink($imagepath); //delete the original file


 

im actually refering to this article

http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php

 

dont know how to use it.

still confused, never actually used image resize before nor got too much idea

 

i did this

 

$image = new SimpleImage();

$image->load($imagepath);

$image->resize(204,250);

$image->save($_FILES["image"]["name"]);

 

but i get

 

Parse error: parse error in C:\wamp\www\edit\index.php on line 558

here is my whole coding

 

$target = "images_thumbs/";
$randomnum=rand(0000,9999);
$target = $target.getnick_username($username).$randomnum;
$target = $target.basename($_FILES['ad_image']['name']) ;
$ok=1;

if (file_exists("images_thumbs/" . $_FILES["ad_image"]["name"]))
      {
echo "<p align=\"center\">";
      echo $_FILES["file"]["name"] . "Oops file name already exists<br/> kindly rename your picture and upload again. <br/>";

echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>";
echo "</p>";    
}else{


    $image = new SimpleImage();
$image->load($imagepath);
$image->resize(204,250);
$image->save($_FILES["image"]["name"]);

//If everything is ok we try to upload it
else{
if(move_uploaded_file($_FILES['ad_image']['tmp_name'], $target)){
echo "<p align=\"center\">";

echo "The file ". basename( $_FILES['uploadedfile']['name']). " Picture uploaded successfully.<br/><br/><b>$target <br/>";
echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>";
echo "</p>";
}
else{
echo "<p align=\"center\">";

echo "Sorry, there was a problem uploading your file.<br/>";
echo "</p>";
}
}

 

 

here is my whole coding

 

$target = "images_thumbs/";
$randomnum=rand(0000,9999);
$target = $target.getnick_username($username).$randomnum;
$target = $target.basename($_FILES['ad_image']['name']) ;
$ok=1;

if (file_exists("images_thumbs/" . $_FILES["ad_image"]["name"]))
      {
echo "<p align=\"center\">";
      echo $_FILES["file"]["name"] . "Oops file name already exists<br/> kindly rename your picture and upload again. <br/>";

echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>";
echo "</p>";    
}else{


    $image = new SimpleImage();
$image->load($imagepath);
$image->resize(204,250);
$image->save($_FILES["image"]["name"]);

//If everything is ok we try to upload it
else{
if(move_uploaded_file($_FILES['ad_image']['tmp_name'], $target)){
echo "<p align=\"center\">";

echo "The file ". basename( $_FILES['uploadedfile']['name']). " Picture uploaded successfully.<br/><br/><b>$target <br/>";
echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>";
echo "</p>";
}
else{
echo "<p align=\"center\">";

echo "Sorry, there was a problem uploading your file.<br/>";
echo "</p>";
}
}

 

Seeing this, I think you don't know what you are doing. Although suggested previously, your extension is still missing.

The resize-class you mention re-saves the resized picture. If you give it a name as you do, you will never know where it will be saved.

If you say 'Parse error: parse error in C:\wamp\www\edit\index.php on line 558' nobody but you can guess what line that is.

You have to provide more information, and take the advices you get a bit more seriously. They are meant to help you. :-\

Okay, I'll try to guide you through it:

[*]from the site you mentioned, (http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php) you copy ALL of the text from the first file (below 'The code') and save it on your computer with the name SimpleImage.php

 

[*]In the top of your own php-file, the one where you are busy with uploading your picture, you enter: include('SimpleImage.php');

You may have to add a path to that file, depending on the location where you saved it.

 

[*]

At this moment that complete class SimpleImage is now part of your own coding.

 

[*]

At the moment you want to resize an image, that class wants to know 3 things: the name of the picture you want to resize, the size you want, and the name you want to give to the resize picture.

 

[*]

first you start the class with:

$image = new SimpleImage();        // your copy of the class is now called $image

 

[*]

Now you tell that class the name of your picture:

$image->load('picture.jpg');          // replace 'picture.jpg' with the name of your picture. This may also be a variable.

 

[*]

Next you tell the class what size you want:

$image->resize(250,400);            // take a guess ...

 

[*]

Now give the class the name of the resized picture and tell it to do it's job:

$image->save('picture2.jpg');      // I think it is unwise to give it the same name.

 

 

Got it now?

 

is this correct?

 

$target = "images_thumbs/";
$randomnum=rand(00000000,99999999);
$oldname = $target.$randomnum.getnick_id($id).$randomnum;
$newname = $oldname.$randomnum.basename($_FILES['ad_image']['name']) ;
$ok=1;

    $target= new SimpleImage();
$newname->load($newname);
$newname->resize(204,250);	
    $newname->save($target);

 

guess not i get this error Fatal error: Call to a member function load() on a non-object in C:\wamp\www\edit\index.php

is this correct?

 

$target = "images_thumbs/";
$randomnum=rand(00000000,99999999);
$oldname = $target.$randomnum.getnick_id($id).$randomnum;
$newname = $oldname.$randomnum.basename($_FILES['ad_image']['name']) ;
$ok=1;

    $target= new SimpleImage();
$newname->load($newname);
$newname->resize(204,250);	
    $newname->save($target);

 

guess not i get this error Fatal error: Call to a member function load() on a non-object in C:\wamp\www\edit\index.php

 

Did you include the complete class as I mentioned earlier?

 

Put the next line after    $oldname = $target.$randomnum.getnick_id($id).$randomnum;

echo 'oldname='.$oldname.'<br/>';

 

and put this line after  $newname = $oldname.$randomnum.basename($_FILES['ad_image']['name']) ;

echo 'newname='.$newname.'<br/>';

 

Then you see what you made of it.

 

Now you can see what's wrong.

 

$oldname=$_FILES['ad_image']['name'];
$newname="images_thumbs/".rand(00000000,99999999).getnick_id($id).$_FILES['ad_image']['name'];

$image= new SimpleImage();
$image->load($oldname);
$image->resize(204,250);	
$image->save($newname);

did this

$oldname = $target.$_FILES['ad_image']['name'];
$newname = $oldname.$randomnum.basename($_FILES['ad_image']['name']) ;

$ok=1;
$image= new SimpleImage();
$image->load($oldname);
$image->resize(204,250);	
$image->save($newname);

 

and i get error

 

Warning: getimagesize(images_thumbs/Water lilies.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:\wamp\www\edit\image_resize.php on line 14

 

Warning: imagesx() expects parameter 1 to be resource, null given in C:\wamp\www\edit\image_resize.php on line 46

 

Warning: imagesy() expects parameter 1 to be resource, null given in C:\wamp\www\edit\image_resize.php on line 49

 

Warning: imagecopyresampled() expects parameter 2 to be resource, null given in C:\wamp\www\edit\image_resize.php on line 68

 

 

oh yes i removed basename etc this is how i did

 

$oldname = $_FILES['ad_image']['name'];

$newname = $target.$randomnum.getnick_uid($uid).$_FILES['ad_image']['name'] ;

 

$ok=1;

$image= new SimpleImage();

$image->load($oldname);

$image->resize(204,250);

$image->save($newname);

 

 

and the resize_image.php is in the same dir why is it not being found? lol crazy this is

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.