Jump to content

Creating a file name or directory with a int


sturbitt

Recommended Posts

I am trying to save my thumbnails but I need to save them with the size that they are in the path of the directory or in the file name, however everytime I insert the interger into the string my script stops working. I have tried to convert the int to string with strval() but it didnt work either. Here is one of the attempts I have made:

 

$trgdir = "_thumbs\\$directory";

if(!(file_exists("$trgdir")))
{
mkdir("$trgdir");
}

$sizeandfile = strval($thumbsize);
$sizeandfile = "$sizeandfile$image";

$trgfile = "$trgdir\\$image";

if(!(file_exists("$trgfile")))
{
imagejpeg($thumb, $trgfile);
}

 

I have tried loads of thing like concating strings and thing but to no avail.

 

Cheers

 

Steven

Link to comment
Share on other sites

Thanks for the suggestion but its still not working. My main problem is I don't get error message as the script is dealling with images and all I get is no picture displayed. I am going to try and build another script with just making directories bit in it and see if I can get an error message. Any other suggestions in the mean time?

 

Thanks again for your help.

 

 

Link to comment
Share on other sites

the easy way mate now all you do is the database connection then echo pic via html img src ok.

 

1. make folder new_upload.

 

2. call the script upload.php

 

test it without the database first ok.

 

<?php

// database connection.

//$db=mysql_connect("locahost","username","password");
//mysql_select_db("database_name",$db);

//random number

$num="123456";
$num=rand(000000,111111);

// directory path.

$uploaddir = 'upload_new/';

// get the dir to send file to and the file name.

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

$file=$uploadfile;

$ext = substr($file, -4);

$uploadfile=$uploaddir.$num.$ext;

@rename($file,$uplaodfile);

// if all the conditions are correct send the file to the directory.

if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)){


//database protection.

//$num=addslashes($_POST['num']);

//query insert.

//$query="insert into colmn_name ('uplaodfile')values('uploadfile)";
//$result2=mysql_query($query);


// success echoed

echo " <font color='red'>File is valid, and was successfully uploaded.</font>";

}else {

//unsuccesfull echoed

echo "<font color='red'>File was unsuccesful sorry</font>";

}

// show the form.
   
echo"
<form enctype='multipart/form-data' action='upload.php' method='POST'>
   
<input type='hidden' name='MAX_FILE_SIZE' value='30000000000000000000000'>

send this file <input name='userfile' type='file' >
    
<input type='submit' name='submit' value='Send File'>

</form>";

?>

Link to comment
Share on other sites

Thanks for the help! I was looking at possibly using the database some how but I am not very good with DBs (not my thing).

 

The $image is the thumb nail I have already generated the picture. All I am tring to do is save that file to disk so that the next time I need it I don't need to regenerate the picture (hopefully speeding up my web site). So My plan was to create a "_thumbs" directory in the root of the web site and save all my thumbnails into that in the same directory structure as the rest of the web site (to avoid duplication).

 

I can do this, but I also offer the ability to view the picture in different sizes (small medium and large) for this I just reuse the thumbnail generation scripts but do it bigger. So what I would like to do is put the size of the image stored in the file name or directory structure: i.e:

 

_thumbs\150\testdir\test.jpg

 

or

 

_thumbs\testdir\150test.jpg

 

But every time I mention the $imagesize variable anywhere the whole thing stops working - it works fine without it!

 

I will try and digest the DB solution with the upload script but its getting frustrating as to why my script isn't working.

 

Thanks again! 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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