/    Sign up×
Community /Pin to ProfileBookmark

PLEASE DIRE NEED OF HELP, FILE SCRIPT W/ Images

OMG I NEED HELP!!!

THere is this script im making, and i have been working on it for 10 hours! 10 HOURS!! No Joke.. and I haven’t made ANY progress.. all that i have made is more confusion on myself..

What the script does is takes a file, then resizes it, then saves it.. then saves the orignal.. so you have two files.. one that is resized.. and one that isn’t.. right?

What is happening is that some files that I upload don’t work.. Most of them otu of PS.. but when i click upload.. It gets the file.. then it moves it to the tmp dir I have set on my server.. then it makes the resize image (but it turned out black) and it makes the orignal image.. and it gives me an error saying it can’t write to the file.. IF youre thinking the phtoos arecorrupted, I have checked multipul times, and their not. I am about to blow a fuse! ?

I have debugged this scrtipt so much, i have discovered that waht is happening, why it cant write to the file. The $image_buffer doesn’t get set.. there is nothing that is being written.. you have no clue how confused i am..

the script is in the next post.. becuase it wouldnt fit.

its annoying, and keep in mine im practally new and i dont know all of the advanced ways of doing stuff.. I work with what I have, and thats prb why it doesnt work..

ANYWAYS!! SOMEONE PLEASE HELP MEEE ? Much appreciated. any BTW a lot of the stuff is commented out because I was trying new things to see why it was doing what it was..

Thanks for your time!

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@Kyleva2204authorJul 28.2005 — Here is the script:
[code=php]<?php
if ($_GET[page] == "images"){
ini_set('upload_tmp_dir','/www/o/p/optimalconnection.net/psp/htdocs/tmp/');
if ($_GET[genre]){
$page_title = "$_GET[genre] Images";


if ($_GET[sp]){
$images_show_per_page = $_GET[sp];
}
else {
$images_show_per_page = "6";
}
if ($_GET['p']){
$images_limit1 = ($_GET['p'] * $images_show_per_page) - $images_show_per_page;
$images_limit2 = $images_show_per_page;
}
else {
$images_limit1 = "0";
$images_limit2 = "$images_show_per_page";
}
if ($_GET['p']){
$new_imagenl = $_GET['p'] + 1;
}
else {
$new_imagenl = 2;
}

$old_imagenl = $_GET['p'] - 1;
function check_next_image($current_number, $next_number, $show_per_page, $conn){
$current_number = $current_number + $show_per_page;
$next_number = $show_per_page;
$check_sql = "SELECT * FROM images where type = '$_GET[genre]' limit $current_number, $next_number";
$check = mysql_query($check_sql, $conn);
if (mysql_num_rows($check) >= "1"){
return true;
}
else {
return false;
}
}
$images_posts_number = 0;
$disable_images_next = "0";
if ($disable_images_next == "0" and check_next_image($images_limit1, $images_limit2, $images_show_per_page, $conn)){
$image_next = "<a href="./?module=images&page=images&genre=$_GET[genre]&p=$new_imagenl">next ></a>";
}
else {
$image_next = "next >";
}
if ($images_limit1 > 1){
$image_back = "<a href="./?module=images&page=images&genre=$_GET[genre]&p=$old_newnl">< back</a>";
}
else {
$image_back = "< back";
}





$grab_photos_sql = "SELECT * FROM images where type = '$_GET[genre]' LIMIT $images_limit1, $images_limit2";
$grab_photos = mysql_query($grab_photos_sql, $conn) or die(mysql_error());
$page_text .= "
<table width="100%" border="0" cellspacing="2" cellpadding="0" height="100%">
<tr height="73">
";
$number = 0;
while ($photo = mysql_fetch_array($grab_photos)){
$title = $photo['title'];
$url = $photo['url'];
$url_d = $photo['down_url'];
if ($number == "3"){
$page_text .= "</tr>n<tr height="73">";
$number = 0;
}
$page_text .= "<td align="center" valign="top" height="73" width="135"><A href="$url"><img src="$url_d" alt="" height="73" width="135" border="0"><br>$title</a></td>n";
$number ++;
}
for ( ; $number <= 2 ; $number++){
$page_text .= "<td width="135">&nbsp </td>";
}
$page_text .= "
<tr>
<td valign=middle align=center colspan=3>$image_back : $image_next</td>
</tr>
<tr>
<td valing=middle align=center colspan=3>
";
$grab_genres_sql = "SELECT DISTINCT type from images";
$grab_genres = mysql_query($grab_genres_sql, $conn) or die(mysql_error());
$number = 0;
while ($genres = mysql_fetch_array($grab_genres)){
$genre = $genres['type'];
if ($number == 5){
$page_text .= "<br>n";
$number = 0;
}
if ($number == 0){
$page_text .= "<A href="./?module=images&page=images&genre=$genre">$genre</a>";
}
else {
$page_text .= " : <A href="./?module=images&page=images&genre=$genre">$genre</a>";
}
$number++;
}
$page_text .= "
</td>
</tr>
<tr>
<td><a href="./?module=images&page=images&action=upload">Upload an image</a></td>
</tr>
</table>";

}
else if ($_GET[action] == "upload"){
if($_POST[submit]){
function save_file($image, $status, $new){
touch($new);
//chmod($new, '0755');
if (is_writable("$new")){
$fp = $new;
$fp2 = fopen($fp, 'w+') or die ("<center><font size=3 face=aria>We were unable to open the file for editing.</font></center>");
fwrite($fp2, $image) or die("<center><font size=3 face=aria>We were undable to write to the file. $new</font></center>");
fclose($fp2);
$page_text .= "done";
}
else {
$page_text .= "The File is not writable.";
}
}
function open2($fileloc){
$file_name = explode(".", $fileloc);
switch ($file_name[1]){
case "jpg":
return imagecreatefromjpeg($fileloc);
break;
case "jpeg":
return imagecreatefromjpeg($fileloc);
break;
case "gif":
return imagecreatefromgif($fileloc);
break;
case "png":
return imagecreatefrompng($fileloc);
break;
case "tiff" || "tif" || "bmp":
return false;
break;
default:
return false;
}
}
$filename = $_FILES['myfile']['name'];
$filesize = $_FILES['myfile']['size'];
$filetype = $_FILES['myfile']['type'];
$file_tmp = $_FILES['myfile']['tmp_name'];
$file_err = $_FILES['myfile']['error'];

$number1 = rand(0,9);
$number2 = rand(0,9);
$number3 = rand(0,9);
$number4 = rand(0,9);
$number5 = rand(0,9);
$number6 = rand(0,9);
$number7 = rand(0,9);
$number8 = rand(0,9);
$number9 = rand(0,9);
$number10 = rand(0,9);
$file_extension = explode(".", $filename);
$filename2 = $number1 . $number2 . $number3 . $number4. $number5. $number6. $number7 . $number8 . $number9 . $number10 . "." . $file_extension[1];
move_uploaded_file($file_tmp, './tmp/'. $filename2);
$fileloc = "./tmp/" . $filename2;
//chmod("./tmp/" . $filename2, '0755');
if (imagecreatefromjpeg($fileloc) || imagecreatefromgif($fileloc) || imagecreatefrompng($fileloc)){
if ($file_extension[1] == "jpeg" || $file_extension[1] == "jpg"){
$image2= imagecreatefromjpeg("./tmp/" . $filename2);
}
else if ($file_extension[1] == "gif"){
$image2= imagecreatefromgif("./tmp/" . $filename2);
}
else if($file_extension[1] == png){
$image2= imagecreatefrompng("./tmp/" . $filename2);
}
$thumb = imagecreate("135", "73");
list($width2, $height2) = getimagesize("./tmp/" . $filename2);
imagecopyresized($thumb, $image2, 0, 0, 0, 0, "135", "73", $width2, $height2);
ob_start();
ImageJPEG($thumb);
$image_buffer = ob_get_contents();
ob_end_clean();
ImageDestroy($thumb);

ob_start();
ImageJPEG($image2);
$image_buffer2 = ob_get_contents();
ob_end_clean();
ImageDestroy($image2);
//unlink("./tmp/" . $filename2);
//echo "$image_buffer";
$replace = array(
"!" => "",
"@" => "",
"#" => "",
"$" => "",
"%" => "",
"^" => "",
"&" => "",
"*" => "",
"(" => "",
")" => "",
" " => "_",
"<" => "",
">" => "",
"," => "",
"/" => "",
"\" => "",
"|" => "",
"[" => "",
"{" => "",
"]" => "",
"}" => "",
":" => "",
";" => "",
"-" => "",
"=" => "",
"+" => "",
""" => "",
"'" => "",
"." => "",
"n" => ""
);
$newfname = str_replace(array_keys($replace), array_values($replace), $_POST[name]);
save_file($image_buffer, "", "./images/" .$newfname."_r.jpg");
save_file($image_buffer2, "", "./images/" .$newfname.".jpg");
$add_to_sql = "INSERT INTO images (id, title, url, down_url, user, type) VALUES ('', '$_POST[name]', './images/$newfname.jpg', './images/" . $newfname . "_r.jpg', 'DJ Craze', 'Test');";
mysql_query($add_to_sql, $conn) or die("We encounted a problem when adding your image to the database.");
$page_text .= "Successfully added $_POST[name]!";
}
else {
$page_text .= "invalid file type;";
}
}
else {
$page_text .= "
<form method=post action=./?module=images&page=images&action=upload enctype=multipart/form-data>
Select an image: <input type=file name=myfile><br>
Give it a name: <input type=input name=name><br>
<input type=submit value=Go! name=submit>
</form>
";
}
}
else {
$page_title .= "Images";
$grab_genres_sql = "SELECT DISTINCT type from images";
$grab_genres = mysql_query($grab_genres_sql, $conn) or die(mysql_error());
$number = 0;
$page_text .= "<center>";
while ($genres = mysql_fetch_array($grab_genres)){
$genre = $genres['type'];
if ($number == 5){
$page_text .= "<br>n";
$number = 0;
}
if ($number == 0){
$page_text .= "<A href="./?module=images&page=images&genre=$genre">$genre</a>";
}
else {
$page_text .= " : <A href="./?module=images&page=images&genre=$genre">$genre</a>";
}
$number++;
}
$page_text .= "<br><br><a href="./?module=images&page=images&action=upload">Upload an image</a>";
$page_text .= "</center>";
}
}
?>[/code]
Copy linkTweet thisAlerts:
@bokehJul 28.2005 — Even though the source files seem OK try openning one of the ones giving a problem with a different image editor (not photoshop). Make a very minor change and then save and upload that file. My bet is the problem will be gone.
Copy linkTweet thisAlerts:
@Kyleva2204authorJul 29.2005 — Even though the source files seem OK try openning one of the ones giving a problem with a different image editor (not photoshop). Make a very minor change and then save and upload that file. My bet is the problem will be gone.[/QUOTE]
No workie ?.. I opend it in paint, and addd a dot.. and it gave me the same error... So I tried to make a fresh image in Paint, and that didint work.. so then I was like.. is this thing wokring at all? and I uploaded one of the ones that DOES work.. and of course, it worked ?
Copy linkTweet thisAlerts:
@BeachSideJul 29.2005 — so what you are saying is that this only sometimes works while other times it does not?
Copy linkTweet thisAlerts:
@Kyleva2204authorJul 29.2005 — 
  • * sigh * well, once again I figured it out.. and its a dumb A** error... my fault too, and i want to right now kill the man who invited case-sensitive... Yeah thats right... it was a Case-Sensitive problem.. check back on my code. I was looking for images that ended in jpg and jpeg.. not JPG and JPEG.. yeah Dumb right? 12 hrs of work, and its a dumb case-sensitive problem.. Lucky me ?
  • Copy linkTweet thisAlerts:
    @BeachSideJul 29.2005 — I love it when that happens :eek:
    Copy linkTweet thisAlerts:
    @Kyleva2204authorJul 29.2005 — yeah yeah, well thanks for your time in trying to help me! :-D

    Peace out
    ×

    Success!

    Help @Kyleva2204 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.15,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...