Jump to content

upload scrip blank


chanfuterboy

Recommended Posts

Hi,

 

I was working on a uplaod script, after i upload a picture in a form in a separate page, the upload script keep in blank why? should i mist something?

 

<?php

 

// if something was posted, start the process...

if(isset($_POST['upload']))

{

// define the posted file into variables

$name = $_FILES['picture']['name'];

$tmp_name = $_FILES['picture']['tmp_name'];

$type = $_FILES['picture']['type'];

$size = $_FILES['picture']['size'];

 

// get the width & height of the file (we don't need the other stuff)

list($width, $height, $typeb, $attr) = getimagesize($tmp_name);

   

// if width is over 600 px or height is over 500 px, kill it   

if($width>600 || $height>500)

{

echo $name . "'s dimensions exceed the 600x500 pixel limit.";

echo ?> <a href="form.html">Click here</a> to try again. <? ;

die();

}

// if the mime type is anything other than what we specify below, kill it   

if(!(

$type=='images/jpeg' ||

$type=='images/png' ||

$type=='images/gif'

)) {

echo $type .  " is not an acceptable format.";

echo ?> <a href="form.html">Click here</a> to try again. <? ;

die();

}

 

// if the file size is larger than 350 KB, kill it

if($size>'350000') {

echo $name . " is over 350KB. Please make it smaller.";

echo ?> <a href="form.html">Click here</a> to try again. <? ;

die();

}

// if your server has magic quotes turned off, add slashes manually

if(!get_magic_quotes_gpc()){

$name = addslashes($name);

}

 

// open up the file and extract the data/content from it

$extract = fopen($tmp_name, 'r');

$content = fread($extract, $size);

$content = addslashes($content);

fclose($extract); 

// connect to the database

include "connect.php";

 

// the query that will add this to the database

$addfile = "INSERT INTO files (name, size, type, content ) ".

          "VALUES ('$name', '$size', '$type', '$content')";

 

mysql_query($addfile) or die(mysql_error());

 

// get the last inserted ID if we're going to display this image next

$inserted_fid = mysql_insert_id();

 

mysql_close(); 

 

// display the image

?>

<div align="center">

    <strong><? echo $name; ?><br>

    </strong><img name="<? echo $name; ?>" src="getpicture.php?fid=<? echo $inserted_fid; ?>" alt="Unable to view image #<? echo $inserted_fid; ?>">

    <br>

    <a href="form.html">upload more images</a>

</div>

<?

// we still have to close the original IF statement. If there was nothing posted, kill the page.

}else{die("No uploaded file present");

}

?> 

Link to comment
Share on other sites

Just thinking the exact same thing. Or check your PHP error log, it should tell you. If there's no errors, try to do a var_dump($_POST['upload']) and see what you get (if anything).

 

Put this in the top of the script that processes the upload:

 

error_reporting(E_ALL);

 

And report back :)

Link to comment
Share on other sites

So how exactly is your script supposed to work, you state something about "uploading a picture in a form in a separate page".

 

Does the upload itself actually work or no? If you can give us the URL where you are running this script it might be helpful so we can see the code in action.

Link to comment
Share on other sites

So how exactly is your script supposed to work, you state something about "uploading a picture in a form in a separate page".

 

Does the upload itself actually work or no? If you can give us the URL where you are running this script it might be helpful so we can see the code in action.

 

Pretty sure we're not allowed to self-promote around here, even if it's in order to help solve coding problems...not sure if I'm wrong about that rule..

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.